Difference between revisions of "Formatting"

From Progzoo
Jump to navigation Jump to search
 
Line 1: Line 1:
 
{{String Functions}}
 
{{String Functions}}
 +
You can format numbers using the <code>String.format</code> method.
 +
See [[Format Printing]] for details of some other options that are available.
 
<question>
 
<question>
 
You can build a string using format. The % values are substituted.
 
You can build a string using format. The % values are substituted.
 +
 +
The output is be:
 +
12,345
 
<shell>
 
<shell>
 
public class P{
 
public class P{
Line 9: Line 14:
 
}}
 
}}
 
</shell>
 
</shell>
<prog>String s = String.format("With commas %,d",12345);
+
<prog>String s = String.format("%,d",12345);
 
System.out.println(s);
 
System.out.println(s);
 
</prog>
 
</prog>
 
</question>
 
</question>

Latest revision as of 23:18, 16 November 2008

You can format numbers using the String.format method. See Format Printing for details of some other options that are available.

You can build a string using format. The % values are substituted.

The output is be:

12,345


[Font] [Default] [Show] [Resize] [History] [Profile]