I have a BigDecima
l 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?
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;