gbzhhu
asked on
BigDecimal SetScale() How?
I am using BigDecimal format and when I say:
BigDecimal nCurrentNumber = new
BigDecimal ("9");
BigDecimal nTemp = new
BigDecimal ("5");
nCurrentNumber = nCurrentNumber.divide(nTem p, BigDecimal.ROUND_HALF_UP);
nCurrentNumber.setScale(28 ,BigDecima l.ROUND_UP );
I get a result of 2, but I am expecting
1.8 I doesn't actually give me any decimal point - why? all operations return a number with no decimal places.
Can someone help me - urgent
Thanks
BigDecimal nCurrentNumber = new
BigDecimal ("9");
BigDecimal nTemp = new
BigDecimal ("5");
nCurrentNumber = nCurrentNumber.divide(nTem
nCurrentNumber.setScale(28
I get a result of 2, but I am expecting
1.8 I doesn't actually give me any decimal point - why? all operations return a number with no decimal places.
Can someone help me - urgent
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Superp answer jerch
Thanks
Thanks
you're welcome :)
Just change
nCurrentNumber.divide(nTem
to
int scale = 2;
nCurrentNumber = nCurrentNumber.divide(nTem
This will produce 1.80.
The scale is the number of digits to the right of the decimal point. Of course it depends on what precision you want.
best regards...
Jerson