Java – decimalformat() and problems with Russian computers

I have a BigDecimal, and I convert it to string to make some modifications

DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setParseBigDecimal(true);
Amt = (BigDecimal) decimalFormat.parse(amount);

Finally, I hope my BigDecimal is like this, such as "135.40". It works, but on the Russian computer, I get "135.00" I don't understand why. What kind of mistake is this?

Solution

The decimal separator in the Russian language environment is This is why the number is truncated This is not valid for the Russian locale

decimalFormat. Parse ("135,40") should provide you with the required BigDecimal

If you want to use To parse a number, change the locale of decimalformat:

NumberFormat formatter = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat decimalFormat = (DecimalFormat)formatter;
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
分享
二维码
< <上一篇
下一篇>>