aspose file tools*
The moose likes Beginning Java and the fly likes How do I print a formatted number? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I print a formatted number?" Watch "How do I print a formatted number?" New topic
Author

How do I print a formatted number?

Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
I feel a bit stupid about this, but I haven't figured out how to printed a formatted number to the console in Java. I was hoping for a "printf" or something like it. Here is a sample of what I'd like to do:

which prints out an accurate but useless table of numbers with 15 digits of accuracy. How can I make it print out only one or two digits?
Thanks in advance.


Timothy Chen Allen
Learn Spanish in Washington, DC
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Wouldn't it be neat if there was an interface called NumberFormat that would have implementations to format numbers?
http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html
Enjoy!


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
Thomas, you are the man. Not only will that do what I want, it will do it in my localization (Spain) which means numbers like "32,5". Thanks very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I print a formatted number?