PDA

View Full Version : Urgent help needed !


sunilkamadolli
Apr29-04, 12:56 PM
hey everybody, i was writing a java program and i could not figure out how to round a number[double] to 4 decimal places...i tried a lot of things

the math function's round function rounds the double to one decimal place so that does not work.

i tried various algorithms like dividing by .0001 and then rounded it and stored it into an integer and then divided the integer by 1000...still not working

please help me out...even non-java programmers can help by telling me the algorithm....thank u.

pig
Apr29-04, 03:11 PM
i tried various algorithms like dividing by .0001 and then rounded it and stored it into an integer and then divided the integer by 1000...still not working

Divide by 10000..

DarkAnt
Apr29-04, 03:49 PM
yeah its kinda crazy. what you have to do is multiply that number by 1000, do the round function and then divide by 1000

sunilkamadolli
Apr29-04, 11:48 PM
yup i should have done the round 1st then divide by 1000...thanks DarkAnt...

if any1 wants to look at the code here is some webpage i found

http://www.dickinson.edu/~braught/courses/cs132s01/classes/code/Rounding.src.html