Di you understand that batteries are made up of groups in series? Like 48V is 13 groups, and 36V is 10 groups? And you know that a group has at minimum one cell, but usually 3 to 5 cells.
The AH rating of an ebike battery is simply the Ah rating of each cell x the number of cells in the group. Take a 40 cell 36V10AH pack. We know it's 10 groups, so 4 cells per group. We can divide 10AH by 4 to learn it uses middling quality 2.5AH cells. Similarly a 52 cell 48V10AH pack could also use the same cells.
Now that you have digested the above, the WH rating is the batteries AH rating x nominal voltage. A 36V10AH pack is 360WH. A 48V10AH pack is 480 WH. If the first pack had 40 cells, the second one will have 52 cells. Those extra 12 cells give you another 120 WH.
Yes, if (and only if you maintain the same speed), a 36V bike and a 48V bike use the same WH per mile. So a 48V10AH pack does give more range than a 36V10AH pack. More speed too.
In general, you can't get the full WH out of a pack unless you're willing to kill it. The AH rating on a bare cells is determined by testing it from full charge (4.2V) down to its safest low charge (2.5 to 2.7 volts). For reliability, a good ebike controller shuts off a battery when the average cell voltage is 3.0-3.2 volts. So you might leave 10-20% of the available WH still in the cells. If you put a dumb light bulb on your ebike battery, you can run it down til it's flat and it might not be able to recharge.
If not happy with the range, yes, buy a second battery with more WH that fits, or buy a spare battery and carry it. Or ride slower.