| | |
Number Rounding
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2005
Posts: 31
Reputation:
Solved Threads: 0
Can someone help me create a rounding routine? I have some mathematical calculations being done in a program that the final result is a double. The only trouble is, is when I want to display it, there are too many digits appearing. I have searched the Sun web site and others without finding anything that will help.
Java Syntax (Toggle Plain Text)
import java.text.DecimalFormat; public class DecimalTest { public static void main(String[] args) { DecimalFormat dfMoney = new DecimalFormat("$###.##"); DecimalFormat df2 = new DecimalFormat("###.##"); DecimalFormat df3 = new DecimalFormat("###.###"); DecimalFormat df4 = new DecimalFormat("###.####"); System.out.println(dfMoney.format(294.489003)); System.out.println(df2.format(294.489003)); System.out.println(df3.format(5935.393432)); System.out.println(df4.format(1323.23423)); } }
Here is the output:
$294.49
294.49
5935.393
1323.2342
![]() |
Similar Threads
- memorising requested variables after page reset (PHP)
- Rounding numbers problem (Visual Basic 4 / 5 / 6)
- Division Problem (C#)
- Ambiguity Error, please help. (C++)
- Rounding with Microsoft Visual Studio .NET 2003 (C++)
Other Threads in the Java Forum
- Previous Thread: Adding components to JApplet
- Next Thread: Password Field in a JOptionPane
Views: 12093 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working






