I would like to know how do electronics (ie smartphones,mobilephones,laptops etc) know exactly what % of juice is left in the battery and how long that juice is going to last.

Thank you in advance

Such 'fuel gage' measurements are often pretty inaccurate on many consumer devices. There are two methods commonly used, especially for Li-Po powered devices. The 'low tech' method is to simply measure the battery terminal voltage while in use as LiPo cell has a fairly linear voltage discharge 'curve' of 4.2 at 100% down to 3.0 volts which is the common recommended lowest discharge voltage to use. The more 'higher tech' method is to measure current consumption continuously and integrate the value over time such that one can measure the actual mAH of capacity consumed sense the last full charge.

There is a lot of cheap "high side current sense" chips from TI, LT, Maxim, Microchip, AD, ST. That is what you need. You need a few milliohm resistor (maybe a short pcb trace??) with such HSCS amplifier. Measure the current and voltage with A/D each 10ms and sum it. You'll get roughly the capacity. Just google it..Reading: http://www.maximintegrated.com/app-notes/index.mvp/id/746