Java – convert from numeric string containing comma to int
•
Java
I have such value:
String x = "10,000";
I want to convert it to int. I can convert it by removing the following Comma:
String y = x.replace(",",""); int value1 = Integer.parseInt(y);
But I don't want to do that
Any other suggestions, such as built-in features? Or any other recommended method?
Solution
You can simply say:
NumberFormat.getNumberInstance(Locale.UK).parse(x);
read:
> NumberFormat > Locale. UK and others
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码