2

I've been creating a Battery Status on Android, but the Temperature and the Voltage doesn't come with the Battery Manager, for Example:

I need 28.7ºC, but Battery Manager get 287ºC, in Voltage I need 4.357, but it get 4357, so how do i get this number and insert the point that I need? Thanks!

My code is:

int temperature = intent.getIntExtra("temperature", -1);
int voltage = intent.getIntExtra("voltage", -1);
tshepang
  • 12,111
  • 21
  • 91
  • 136

4 Answers4

4

You can use something like this:

double temperature = intent.getIntExtra("temperature", -1) / 10;
double voltage = intent.getIntExtra("voltage", -1) / 1000;

As per this discussion, unit of measurement are "Tenth of centigrade" and "Millivolts" respectively for temperature and voltage in BatteryManager

Community
  • 1
  • 1
Wand Maker
  • 18,476
  • 8
  • 53
  • 87
1

You can do this by DecimalFormat

DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here.
System.out.println(df.format(temperature/10.0)); // Testing result
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
0

int variables doesn't support floating point. You need to use either double or float variables.

Matthieu Harlé
  • 739
  • 1
  • 13
  • 32
0

Well, then divide them:

float temperature = intent.getIntExtra("temperature", -1)/10;
float voltage = intent.getIntExtra("voltage", -1)/1000;
David Jashi
  • 4,490
  • 1
  • 21
  • 26