LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   rounding a large double to 2 decimal places (https://www.linuxquestions.org/questions/programming-9/rounding-a-large-double-to-2-decimal-places-425489/)

linuxmandrake 03-16-2006 03:33 PM

rounding a large double to 2 decimal places
 
How do I do it in java. Am using 1.4.2 and must do

Matir 03-16-2006 05:08 PM

Magic Google 8-Ball said: http://www.codecomments.com/archive2...-8-537423.html

Fredstar 03-17-2006 03:31 PM

Quote:

Originally Posted by linuxmandrake
How do I do it in java. Am using 1.4.2 and must do

use the DecimalFormat class

DecimalFormat myFormat;
myFormat = new DecimalFormat("0.00") // the 0.00 sets 2 for 2 3 for 3 and so on

then when outputting call it

//if using System.out.println

System.out.println(myformat.Format(2.68546846484));

************************************************
EDIT
************************************************
Sorry rushed in response and thought you were looking to format your output. sorry
which would output 2.68


All times are GMT -5. The time now is 09:14 PM.