...
An alternative approach is to use the BigDecimal type, though it is less efficient performance wise.
Code Block | ||
---|---|---|
| ||
import java.math.BigDecimal; // ... BigDecimal dollar = new BigDecimal("1.0"); BigDecimal dime = new BigDecimal("0.1"); int number = 7; System.out.println ("A dollar less " + number + " dimes is $" + (dollar.subtract( new BigDecimal(number).multiply(dime) )) ); |
...