Java Reference
In-Depth Information
valStr = df.format (q);
System.out.println ( " 1.0/3.0 =" + valStr);
// The# symbol indicates trailing blanks
df.applyPattern ("0.#####");
valStr = df.format (1.0/2.0);
System.out.println ("1.0/2.0 ="+ valStr);
// Fix the number of places in the fraction.
df.applyPattern ("0.00E0");
valStr = df.format (1000.0/3.0);
System.out.println ("1000.0/3.0 ="+ valStr);
// Scientific notation
df.applyPattern ("0.00E0");
valStr = df.format (3.0/4567.0);
System.out.println ("3.0/4567.0 ="+ valStr);
// Negative infinity
df.applyPattern ( " 0.000E0 " );
valStr = df.format ( - 1.0/0.0);
System.out.println ( "- 1.0/0.0 =" + valStr);
// NaN
df.applyPattern ( " 0.000E0 " );
valStr = df.format (0.0/0.0);
System.out.println ("0.0/0.0 ="+ valStr);
....
The following shows the output of DecimalFormatDemo :
1.0/3.0 = 0.333
1.0/3.0 = 0.33333
1.0/2.0 = 0.5
1000.0/3.0 = 3.33E2
3.0/4567.0 = 6.57E 4
- 1.0/0.0 = -?
0.0/0.0 =?
Note that the format() method returns the infinity and Not-a-Number ( NaN )
values (see Section 2.12) as a “? character.
Search WWH ::




Custom Search