Formatted numeric output: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
|||
Line 1,093: | Line 1,093: | ||
<lang java5>public class Printing{ |
<lang java5>public class Printing{ |
||
public static void main(String[] args){ |
public static void main(String[] args){ |
||
double |
double value = 7.125; |
||
System.out.printf("%09.3f", |
System.out.printf("%09.3f",value); // System.out.format works the same way |
||
System.out.println(String.format("%09.3f",value)); |
|||
} |
} |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
<pre>000000007.125 |
<pre>000000007.125 |
||
000000007.125</pre> |
|||
Using <code>NumberFormat</code>: |
Using <code>NumberFormat</code>: |
||
<lang java5>import java.text.DecimalFormat; |
<lang java5>import java.text.DecimalFormat; |