My formula is this:
4.2 per cell is full charge, 3.2 is empty.
voltageNow = your current voltage
minBatteryVoltage = what your batteries voltage would be if it's empty
batteryVoltageRange = the max voltage of your battery pack minus the min voltage of your battery pack
so your current battery percentage = ((voltageNow - minBatteryVoltage)/batteryVoltageRange)*100
a 12s battery would be:
voltageNow = lets say your at 45 volts
minBatteryVoltage = for a 12s, this is 3.2 x 12, which is 38.4
batteryVoltageRange = since the max voltage is 50.4 and the min voltage is 38.4, 50.4 - 38.4 = a 12 volt range
((45 - 38.4)/12)*100 = 55%
It's not perfect, since batteries don't discharge linearly, but besides the first 2 volts and the last volt or 2 (which both drop off quickly), they discharge pretty linearly. I've done plenty of real world testing to confirm that this is mostly accurate, and definitely useful.