DecimalFormat(), probleme with russian computers

khaled djellal :

I have a BigDecimal which I convert to a String to do some modifications on it. At the end I try to convert it back to BigDecimal using this part of the code:

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

At the end I expect my BigDecimal to be like this for example "135.40" and it works, but on a Russian computer I get "135.00". I don't understand why, is this kind of a bug or something?

S.K. :

The decimal separator in Russian locale is ,. That is why the number is truncated at . which is invalid for Russian locale.

decimalFormat.parse("135,40") should give you the desired bigdecimal.

If you want to parse the numbers with ., change the locale of DecimalFormat:

NumberFormat formatter = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat decimalFormat = (DecimalFormat)formatter;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=89777&siteId=1