How can i get the battery temperature with decimal? Actually i can calculate it with
int temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
But in this way the result will be for example 36 °C
.. I want something that show me 36.4 °C
How can i do?
Google says here :
Extra for ACTION_BATTERY_CHANGED: integer containing the current battery temperature.
The returned value is an int representing, for example, 27.5 Degrees Celcius as "275" , so it is accurate to a tenth of a centigrade. Simply cast this to a float and divide by 10.
Using your example:
int temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
float tempTwo = ((float) temp) / 10;
OR
float temp = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0) / 10;
You don't need to worry about the 10 as an int since only one operand needs to be a float for the result to be one too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With