wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Formatting number values code example needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formatting number values code example needed" Watch "Formatting number values code example needed" New topic

Formatting number values code example needed

Chad Eaves

Joined: Apr 09, 2002
Posts: 1
I am trying to figure out how to formate a number with two whole numbers before the decimal place and three decimal places. I have looked at the DecimalFormat class but I have not got the code to work. Does anyone have some example code for how to do formatting?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
DecimalFormat df = new DecimalFormat("00.000");
System.out.println(df.format(2.4300001)); // prints 02.430
would seem to do just what you are trying to do.
Two pointers:
The DecimalFormat documentation describes well how to use DecimalFormat.
The link to the search page to search this forum (and others at JavaRanch) is at the top right of this page. Lots of great information can be found using it - and DecimalFormat is a topic that comes up over, and over, and over...
Good Luck.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link: http://aspose.com/file-tools
subject: Formatting number values code example needed
Similar Threads
String to Long
Unpredicatable rounding decimals using Number Format/ Decimal Format
Decimals not converting to correct fractions
Number Format Specifiers
How to find number of decimal places?