Wednesday, April 17, 2013

[android help] Celsius to fahrenheit android


To convert a float to long


you could just use a casting



(long) custom.getTemperature()


However, if all you have is a String representing a floating point number, you may want to change your convert function, to receive a float instead.-



public static int convertCelsiusToFahrenheit(float celcious){
return Math.round(celcious * 9.0f / 5.0f + 32);
}


And pass



Float.parseFloat(custom.getTemperature())


Don't forget to divide 9.0f / 5.0f instead of 9 / 5, as the last one is an integer division and will always return 1.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...