Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

decimalformat

Thread view: 
(-Peter-) - 09 Feb 2008 15:49 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.