This is not straightforward and it is not at all analogous to a fuel tank in a petrol vehicle because the discharge profile of every battery is different.
The remaining capacity of a battery is measured in KWh but this is impossible to measure so the instrumentation uses the drop in the voltage of the battery as a proxy. But that’s a bit like trying to measure water temperature by sticking your thumb in. So the change from four bars to two does NOT mean that the battery has used half of its capacity.
So how do you know how many miles you have left?
Actually I don’t think you can- you will only know you have run out of juice when the bike stops and for various reasons this might be at a different place each day. I have never had to push one home yet but I do tend to err on the side of caution. There are things you can do to extend range- charge the battery in warm conditions, drive more slowly and decelerate not brake. The last tip in particular should make a lot of difference.
Of course there may be a fault in your battery- if you think there is let us know and we will test it and replace if necessary.