摄氏华氏机器人 [英] Celsius to fahrenheit android
本文介绍了摄氏华氏机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共静态INT convertCelsiusToFahrenheit(长celcious){
返回Math.round(celcious * 9/5 + 32);
}
我想将它设置为我的文本字段。我不能在来设置的值文本字段
,怎么我收到NumberFormatException异常。 如何可以我precision值发送。
holder.textItem.setText(convertCelsiusToFahrenheit(的Long.parseLong(
custom.getTemperature())));
java.lang.NumberFormatException:长期无效32.2222222222222
块引用>解决方案在除了回答有关分析为
浮动
等,注意的setText
过载。当它需要一个int,它是一个资源ID,所以做一个字符串
,并给它:而不是:
holder.textItem.setText(convertCelsiusToFahrenheit(...));
执行
holder.textItem.setText(的String.format(%D,convertCelsiusToFahrenheit(...)));
或者
holder.textItem.setText(的String.format(%d个\\ x00B0 F,convertCelsiusToFahrenheit(...)));
应该给你10°F(未经测试)
public static int convertCelsiusToFahrenheit(Long celcious){ return Math.round(celcious * 9/5 + 32); }
I am trying to set it to my TextField. I am not able to set the value in the
Text Field
, coz i am getting the NumberFormatException. How can i send it with precision values.holder.textItem.setText(convertCelsiusToFahrenheit(Long.parseLong( custom.getTemperature())));
java.lang.NumberFormatException: Invalid long: "32.2222222222222"
解决方案In addition to the answers about parsing as
float
etc, note thatsetText
is overloaded. When it takes an int, it is a resource Id, so make astring
and give it that:Instead of:
holder.textItem.setText(convertCelsiusToFahrenheit(...));
Do:
holder.textItem.setText(String.format("%d", convertCelsiusToFahrenheit(...)));
Or:
holder.textItem.setText(String.format("%d\x00B0 f", convertCelsiusToFahrenheit(...)));
Should give you "10° f" (untested)
这篇关于摄氏华氏机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文