I have to convert a String
(read from excel cell) into BigDecimal
, but I have to consider :
BigDecimal
number will have two decimal digits, so I must form it in that wayBigDecimal num = new BigDecimal(rowCell);
and rowCell has comma as decimal separator I will take an exception...)Could you help me? Thank you in advance
You need to do it by steps:
,
by a dot .
BigDecimal
from this new stringROUND_DOWN
or ROUND_UP
String str = "123,456"; // String 132,456
str = str.replace(',', '.'); // String 132.456
BigDecimal b = new BigDecimal(str); // BigDec 132.456
b = b.setScale(2, BigDecimal.ROUND_DOWN); // BigDec 132.45
If you concat you have :
String str = "123,456";
BigDecimal b = new BigDecimal(str.replace(',', '.')).setScale(2, BigDecimal.ROUND_DOWN);