Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
int dollar = 100;
int dime = 10;
int number = 7;
System.out.println(
  "A dollar less " + number + " dimes is $0." + (dollar - number * dime) + " cents" 
);

This code correctly outputs:

Code Block
A dollar less 7 dimes is $0.30 cents

Compliant Solution

This compliant solution uses the BigDecimal type, which provides exact representation of decimal values. Note that on most platforms, computations performed using BigDecimal are less efficient than those performed using primitive types. 

...