Round Off

A double value has about 15 significant digits.
If you divide  5.0 / 3.0, the result is 1.6666666666666667
For prices (with cents) this is inappropriate.
The answer should be rounded to 2 decimal places:

     Price = 5.0 / 3.0  -->     1.66666666666667
     Multiply by 100   --->    166.666666666667   
     Round to the nearest
          whole number       -->  167
     Divide the result by 100  -->   1.67

Write commands to round off a double price to 2 decimal places.

Solution

   double price = inputDouble("Type a price");

   double cents =  price * 100;

   double rounded =  Math.round(cents);

   double  answer =  rounded / 100 ;