Have you noticed how wrong your laptop or tablet gets this.
Have you noticed how wrong your laptop or tablet gets this. They have vastly more engineering resource than you and they can't get it right. It is not something that ca be accurately predicted. There are too many variables.
I too want to be able to display something on my project before the battery completely dies off...How does one "measure the voltage" programmatically within the sketch?
I think half the trouble is how they estimate the upcoming use. The might have a good handle on Ah left (but I wouldn't know if they do or not) but they seem to take the instantaneous consumption and assume you'll be doing that non-stop until it dies. So if it looks like you have a long time left, as soon as you do something intensive for a few moments, your time left drops drastically based on that heavy load.
Predicting "remaining life" is difficult.OTOH knowing when it's "nearly dead" isn't. Most batteries go down to about 1.1V then drop off very quickly (think "cliff").