### Find precise batter status

Hello everyone! I am working on an application that requires me to find the battery life of computer. I'm aware of finding the integral life, but I need a double/float value, with precision at least to the 10ths place (e.g. 60.3%)

What? Why would you need such integer to hold 60.3%?
I would need a double or float to hold the value. I'm working on a program that requires a precise battery life calculation.
You call win32 GetSystemPowerStatus() API providing a SYSTEM_POWER_STATUS structure.

To get the remaining battery charge in percent just must use the BatteryLifeTime and BatteryFullLifeTime members.

The remaining battery charge in percent is

(RemainingCapacity * 100f) / FullChargedCapacity

for example if the FullChargedCapacity property report a 5266 value and the RemainingCapacity reports a 5039, the reuslt will be 95,68932776 %

http://msdn.microsoft.com/en-us/library/windows/desktop/aa372693(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa373232(v=vs.85).aspx
Alright, wouldn't BatteryLifeTime, and BatteryFullTime be apart of WMI? I know these are the member I need to use, although I don't know how to implement them into my code correctly. (I sadly can't even seem to find a download)

Maybe I'm exploding with newbiness, in any case, thank you for taking my a step ahead.

Also, I have attempted to use the SYSTEM_POWER_STATUS, here is my code.

 12345678910111213 #include #include using namespace std; void main() { SYSTEM_POWER_STATUS pwr; GetSystemPowerStatus(&pwr); cout << pwr.BatteryLifeTime << endl; cout << pwr.BatteryFullLifeTime << endl; cout << pwr.BatteryLifePercent << endl; }

Which outputs
 123 20923 4294967295 E

When my battery is at 69%..

There are two issues, 20923/4294967295!=.69
and "E" instead of an integral value from 1-100. (FIXED)

Even with this resolved, my ultimate issue of trying to find a more precise battery reading remains.
Last edited on
Topic archived. No new replies allowed.