Thursday, 5 September 2013

Bigdecimal restriction whole and decimal part

Bigdecimal restriction whole and decimal part

How do you restrict the whole part to 15 and decimal part to 8 like 15.8
using BigDecimal
For Example:
String quant= "1000";
String price = "123456789012345.12345678";
final int contant = 100;
BigDecimal bd1;
BigDecimal bd2;
String value = "";
bd1 = new BigDecimal(price).multiply(new BigDecimal(quant));
bd2 = bd1.divide(new BigDecimal(contant));
value = bd2.toPlainString();
Output value coming as 1234567890123451.2345678. So can I restrict the
whole part up to 15 and decimal part up to 8.

No comments:

Post a Comment