go to previous page   go to home page   go to next page highlighting
DecimalFormat numform = new DecimalFormat("000,000.00"); 
System.out.println( "Num = " + numform.format(98765.432) );

Answer:

Num = 098,765.43

Negative Values

value of double format pattern output string
-123.456
"000.000"
"-123.456"
-123.456
"000.0"  
"-123.5"
-89.008
"0.00"    
"-89.01"
-89.008
"0."       
"-89."
-1.1
"0000.0000"     
-0001.1000"
-89.008
"  0.0"     
"-  89.0"

When a number is negative, a minus sign is output in front of all the characters called for by the format pattern. If there are spaces on the left of the format pattern, they will be output, with the minus sign to the left of them. This is usually an error. See the last example.

 


QUESTION 10:

What does the following fragment write?

DecimalFormat numform = new DecimalFormat("-0.00"); 
System.out.println( "Num = " + numform.format(-924.56) );



go to previous page   go to home page   go to next page