Actual battery capacity cannot be perfectly represented by a percentage calculation..
The percentage probably takes into account history of the device, current discharge rate, etc... to estimate how much you have left..
The fact that you put the same batter back in later and it had more.. does NOT mean that the battery "actually" had more power... it just means the calculation ended up with a higher number (maybe you had less apps running, screen not as bright.. etc).. so the calculation for the percentage is different ... Also, you were just running on a different battery before that.. so, the phone could have been using knowledge about it's discharge rate to determine the current batteries percentage.
This is also VERY evident in Vehicles which estimate "miles until empty"... the calculation that they present is very biased towards current driving conditions... You may drive home and it say you have 10 miles left... then after sitting overnight.. when you start up the car from scratch, it shows 20-30 miles remaining.. but, it's pretty obvious that some Gas-Gremlin didn't come and put more gas in your car over night..
this was very long-winded to say... they are computers performing calculations and are prone to slight error.