Interest Calculations Using BigDecimal

Figure 8.16 reimplements the interest calculation example of Fig. 5.6 using objects of class BigDecimal to perform the calculations. We also introduce class NumberFormat (package java.text) for formatting numeric values as locale-specific Strings—for example, in the U.S. locale, the value 1234.56, would be formatted as "1,234.56", whereas in many European locales it would be formatted as "1.234,56".

 1   // Interest.java 2   // Compound-interest calculations with BigDecimal. 3   import java.math.BigDecimal; 4   import java.text.NumberFormat; 5  6   public class Interest 7   { 8      public static void main(String args[]) 9      {10         // initial principal amount before ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.