As mentioned before, one of the difficulties with introductory
Java is dealing with I/O topics. Java I/O is very powerful but so
elaborate that it is awkward to use for basic tasks like output
of floating point numbers to the console.
In many of our demonstration programs, for example, you likely
noticed that a simple floating point (FP) operation such as a divide
can result in a long fraction when we use the default conversion
of a double
to a String.
In this chapter we will look at tools for formatting of floating
point numbers. This includes both decimal format and scientific
notation.
- DecimalFormat
class in the java.text
package added scientific notation with Java 1.2.
- System.out.printf()
- Java 5.0 added this method, which offers formatted output like
the printf()
function in C. Internally it uses the Formatter
class, which we will discuss in Chapter
9.
- Format
- an opens ource class from the Core Java book series.
- We then list several other independent
classes that provide formatting tools.
Last update: Oct. 23, 2004
|