Solution for How can I parse a string to BigDecimal without considering the leading zeros in java?
is Given Below:
I have this number that I receive as string 000000000007500 and I must pass it to BigDecimal not considering the zeros that are on the left, I have tried to do the following but the result is 0.0, if you could help me please, thank you very much.
BigDecimal bigDecimal = BigDecimal.valueOf ((Double.valueOf (transNum.getAmount ()) / 100));
BigDecimal will ignore leading 0 in the
String constructor just fine, so
new BigDecimal("000000000007500") will represent 7500.
If you want to divide by 100 after that, then do it with the
BigDecimal result = new BigDecimal(transNum.getAmount()) .divide(BigDecimal.valueOf(100), MathContext.UNLIMITED);