字符串转换为整数/浮点/双精度 [英] Convert String to Integer/Float/Double

查看:637
本文介绍了字符串转换为整数/浮点/双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想字符串转换为整数/浮点/双精度,但我得到了一个 NumberFormatException异常

I am trying to convert a string to Integer/Float/Double but I got a NumberFormatException.

我的字符串是 37,78584 ,现在我把它转换到任何一个我得到了 NumberFormatException异常

My String is 37,78584, Now I am converting this to any of them I got NumberFormatException.

我怎么能这样字符串转换为任何人。

How can I convert this string to any of them.

请帮我走出这个问题。

推荐答案

您必须使用适当的区域设置的数量像

You have to use the appropriate locale for the number like

String s = "37,78584";
Number number = NumberFormat.getNumberInstance(Locale.FRENCH).parse(s);
double d= number.doubleValue();
System.out.println(d);

打印

37.78584

这篇关于字符串转换为整数/浮点/双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆