# Multiplication accurary

Hi,

working on a simple problem and wanted to get some ideas of the best way around it.  Essentially I want to solve the following problem:

\$0.75 * 120%

I have tried the following:

``````		BigDecimal bd1 = new BigDecimal(.75);
BigDecimal bd2 = new BigDecimal(.2);
BigDecimal bd3 = new BigDecimal(1);

System.out.println( 0.75 * ( 1 + 0.20) );

System.out.println( .75d *  1.2d );

System.out.println( .75d / 5d * 6d);

System.out.println( 75d * 1.2d /100d);

System.out.println( .75d * (( 1d + 0.2d) * 100d)/100d );``````

With the following output:

0.90000000000000000832667268468867405317723751068115234375
0.8999999999999999
0.8999999999999999
0.8999999999999999
0.9
0.9

for_yan

Look at this recent question with solution:

https://www.experts-exchange.com/questions/27240925/how-to-round.html?sfQueryTermInfo=1+10+30+bigdecim+yan

``````  BigDecimal federalTaxableEarnings =  new BigDecimal(40.0276);
federalTaxableEarnings = federalTaxableEarnings.setScale(2, RoundingMode.HALF_UP);
System.out.println("earning: " + federalTaxableEarnings);``````
I think it should be like that for your code:

bd4 = bd4.setScale(2,RoundingMode.HALF_UP);
System.out.println("bd4: " + bd4);

Let me test.

Yes, this worked for me:
``````BigDecimal bd1 = new BigDecimal(.75);
BigDecimal bd2 = new BigDecimal(.2);
BigDecimal bd3 = new BigDecimal(1);

bd4 = bd4.setScale(2,RoundingMode.HALF_UP);
System.out.println("bd4: " + bd4);
``````

Output:
``bd4: 0.90``
Frosty555

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
CEHJ

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.