Android温度转换强制关闭
我有一个应用程序,其中有一个部分需要将温度从摄氏度转换为华氏度,但由于某种原因,只有几种手机型号(例如 htcdesire 和索尼爱立信 X10)它在这部分崩溃,但我不知道为什么。有人可以帮忙吗?
double cel = x/10;
finalTFF = 9.0f/5.0f * cel + 32.0;
DecimalFormat twoDForm = new DecimalFormat("##.0");
double NfinalTFF = Double.valueOf(twoDForm.format(finalTFF));
return twoDForm.format(NfinalTFF);
I have an app which has a section that needs to convert the temperature from Celsius to Fahrenheit, but for some reason on only a couple phone models (like the htc desire and Sony Ericsson X10) it crashes at this part, but I have no idea why. can anyone help?
double cel = x/10;
finalTFF = 9.0f/5.0f * cel + 32.0;
DecimalFormat twoDForm = new DecimalFormat("##.0");
double NfinalTFF = Double.valueOf(twoDForm.format(finalTFF));
return twoDForm.format(NfinalTFF);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么这么难?
正如我所见,您想将双精度数转换为字符串,所以:
这应该可行:)
Why so difficult?
As I see, you want to convert a double into a string, so:
That should work :)
调用时您可能会收到 NumberFormatException
根据手机上的语言设置小数点分隔符为“。”或者 ”,”。调用valueOf时,只需要“.”被接受。 Keenora 是正确的,代码可以简化,但为了避免代码崩溃,您可以添加一个替换语句,如下所示:
You are probably getting NumberFormatException when calling
Depending on the language settings on the phone decimal separator is "." or ",". When calling valueOf, only "." is accepted. Keenora is correct that the code can be simplyfied, but to avoid the crash in your code you can add a replace statement like so: