<<< The BigDecimal class | Index | The BigDecimal class >>> |
Note: this material is based on examples from online tutorial at www.opentaps.org
Currency calculations require precision of two digits after the decimal point: $5.99
Sometimes a specific type of rounding behavior is needed: tax calculations always require rounding up
Consider a bowl of ice cream that costs $10.00. If local sales tax is 0.0825 (8.25% tax rate) then the tax amount is
$10.00 * 0.0825 = $0.825 -> $0.83
where "->" represents rounding operation. The total charge to the customer becomes $10.83, and the tax collector gets $0.83 of each ice cream bowl sold.
If 1000 bowls are sold, an overpaid tax due to rounding becomes $5:
1000 * ( 0.83 - 0.825 ) = 5.0
<<< The BigDecimal class | Index | The BigDecimal class >>> |