...
Code Block | ||
---|---|---|
| ||
double dollar = 1.00; double dime = 0.10; int number = 7; System.out.println( "A dollar less " + number + " dimes is $" + (dollar - number * dime) ); |
Because the value 0.10 lacks an exact representation in either Java floating-point type (or any floating-point format that uses a binary mantissa), on most platforms, this program prints:
...
Code Block | ||
---|---|---|
| ||
int dollar = 100; int dime = 10; int number = 7; System.out.println( ( "A dollar less " + number + " dimes is " + (dollar - number * dime) + " cents" ); |
This code correctly outputs:
...