delfindelfin

Well, I am assuming p0 as the standard value of pressure at sea level: 1013.25 hPa

That is not a "standard value". It's the average for atmospheric pressure at sea level. If you are expecting it always to be the average value, then your altitude readings are going incorrect, possibly by a substantial amount.

If I take a location near me at the coast, just this week in some very mild weather, the pressure has fluctuated between 1008 hPa to 1018 hPa. Given 12hPa equates to approximately 100m at low altitudes, that's approximately +/- 40m of error.

But in extreme conditions it could be as high as 1085 hPa or as low as 870 hPa in places, which would be -600m or +1200m.

To calculate a meaningful altitude from atmospheric pressure you need to know either:

a) The current

**actual** pressure at sea level, p0, at a location nearby

b) Your starting altitude (at which point you measure the pressure, and so reverse calculate p0)

What kind of altitudes are you wanting to handle? If you are close to the earth’s surface (i.e. not in a balloon or plane or hiking to the top of a mountain), and you do not have the above data, you might as well assume 12hPa per 100m. That is a linear relation, and so easy to do in integer only maths.

Also, if you know your starting altitude you can make a much better estimate using 12hPa/100m as you can remove the error due to current local conditions.