从具有逗号的数字字符串转换为int [英] Convert to int from String of numbers having comma
本文介绍了从具有逗号的数字字符串转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的价值:
String x = "10,000";
我想将其转换为 int
。
我可以通过删除下面的逗号来转换它:
I want to convert this to int
.
I can convert it by removing comma like below:
String y = x.replace(",", "");
int value1 = Integer.parseInt(y);
但我不想像上面那样做。
But I don't want to do it like above.
内置函数等其他任何建议?或者任何其他推荐的方法?
Any other suggestions like inbuilt function? Or any other recommended ways for this?
推荐答案
您可以简单地说:
NumberFormat.getNumberInstance(Locale.UK).parse(x);
阅读:
-
NumberFormat
-
Locale.UK
和其他人。
NumberFormat
Locale.UK
and others.
这篇关于从具有逗号的数字字符串转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文