This section describes how to format numbers and currency. When formatting numeric data, you can use two approaches:
Use the predefined formats available through the NumberFormat class.
Use a pattern for formatting data, such as a String pattern with DecimalFormat. This allows you to format values in a locale-independent way, such as replacing commas with decimal points. You use a pattern String to accomplish this.
There are two main ways to customize numeric values: NumberFormat and DecimalFormat. The former is for simple, straightforward formatting, and the latter is for custom formatting. Listing 18.4 shows how to use NumberFormat for predefined formats and DecimalFormat for customized ...