Our application can get following numbers:
0.1
0.02
0.003
etc.
These values treated by our code as BigDecimal
,as far we operate with money.
There is form on web UI, where user should view these floating parts of prices, transformed to following ones:
1
02
003
The question is,how to trim leading zero
and delimiter character
in input prices. Perhaps BigDecimal
class has standard method something like trimLeadingZeroes(),but can't find any.
UPDATE: trim just leading zero and delimiter symbol
For instance:
1 is 0.1
27 is 0.27
Something like this?
public String getDecimalFractions(BigDecimal value) {
String strValue = value.toPlainString();
int index = strValue.indexOf(".");
if(index != -1) {
return strValue.substring(index+1, strValue.length());
}
return "0";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With