JDK (Java Development Kit) Tutorials
Dr. Herong Yang, Version 5.00

Number Object and Numeric String Conversion

This chapter provides tutorial notes and example codes on numeric string format. Topics include using java.util.NumberFormat.format() method to format numeric values into text strings; using java.util.DecimalFormat.parse() method to parse date strings into objects.

java.util.NumberFormat - Formatting Numeric Values to Strings

java.util.DecimalFormat.parse() - Parsing Strings to Number Objects

Conclusion:

  • java.util.NumberFormat is abstract class, but it supports some predefined numeric string generation formats.
  • java.util.DecimalFormat is a concrete subclass for formatting numeric values into strings and parsing numeric strings into number objects.

Sample programs listed in this chapter have been tested with JDK 1.3.1, 1.4.1 and 1.5.0.

Dr. Herong Yang, updated in 2008
Number Object and Numeric String Conversion