We'd have our own rechargeable battery capacity gauge

How do we make our own rechargeable battery capacity gauge measuring it in mAh in 2-3% tolerance giving output to the simplest 4 digit LCD?

The first step is to be able to read the time from an external clock module in order to count the time of charge and the time of discharge.
Then you need to measure the current, both into the battery and out of the battery. Then compute the net current in and out and subtract that from the listed capacity of the battery.
Paul

You picked a tough project. What you are trying to do is called Coulomb Counting. There is a lot of information online about this listing the pitfalls but very little on the solution. Let us know how you do.

The charge discharge cycle is not 100% efficient- you put more mAh in than you can take out

You'll never get 2-3% tolerance in the real world for charge remaining. Aging, temperature changes and differing discharge/charge rates will all be more than 10% variations typically. Battery electrochemistry is complex and imperfect.

You can measure the charge accurately, but not predict the exact charge left in a
cell or battery, rough indications only.

For some cell chemistries the cell voltage is a useful guide to state of charge, more so than the charge history. For other chemistries the voltage is all but useless.

One problem is how to measure current if this has a large dynamic range - tricky.

The LTC3337 coulomb counter developed by Analog Devices measure the state-of-charge (SoH) of a primary (non-rechargeable) battery by assessing charge flow from the cell. Following is a link. It was published June 2, in electronic design.

https://www.electronicdesign.com/power-management/whitepaper/21165886/electronic-design-when-coulombs-need-counting-tiny-ic-does-it-with-precision?utm_source=EG%20ED%20Analog%20%26%20Power%20Source&utm_medium=email&utm_campaign=CPS210601103&o_eid=2650E7013734E0V&rdx.ident[pull]=omeda|2650E7013734E0V&oly_enc_id=2650E7013734E0V

And don’t forget discharge rate has an effect on capacity ;

( “power” = wrongly labelled here , really energy )

“ You may be wondering why it is that a battery provides more power when it runs longer, rather than less power. It would be natural to think that a battery running for 100 hours should provide fewer amp hours than a battery that only runs for five, because the battery must preserve power to make it last. The truth is that rapidly discharging batteries causes them to produce a lot of heat. This heat negatively affects the battery’s efficiency. Thus, when you rapidly discharge a battery with a C-5 rating, you are losing some of its available power just because the battery gets hot. Meanwhile, the C-100 battery is discharging at a much gentler pace and will be far more efficient.”

And should the remaining capacity % be the % of the current capacity of the battery (which will fall with use) or the % of the capacity when new ?