Hi..
Can anybody help me how to print some output in a beautiful way?
I want to have the decimal format 0,### ALWAYS..
That is, if I for example have a double = 0,1 I want this to be
printed as 0,100, and not 0,1..
How do I force java to print the zeros?
/Peter
Eric Sosman - 09 Feb 2008 16:01 GMT
> Hi..
>
[quoted text clipped - 4 lines]
> That is, if I for example have a double = 0,1 I want this to be
> printed as 0,100, and not 0,1..
NumberFormat fmt = new DecimalFormat("0.000");
System.out.println(fmt.format(0.1));
or
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMinimumFractionDigits(3);
fmt.setMaximumFractionDigits(3);
System.out.println(fmt.format(0.1));

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
(-Peter-) - 09 Feb 2008 16:05 GMT
> > Hi..
>
[quoted text clipped - 18 lines]
> Eric Sosman
> esos...@ieee-dot-org.invalid
Thank you very much :-)
/Peter
Stefan Ram - 09 Feb 2008 23:19 GMT
>0,1 I want this to be printed as 0,100, and not 0,1..
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.printf( "%.03f%n", 0.1 ); }}
0,100