Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Urgent help needed !

  1. Apr 29, 2004 #1
    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.
  2. jcsd
  3. Apr 29, 2004 #2


    User Avatar

    Divide by 10000..
  4. Apr 29, 2004 #3
    yeah its kinda crazy. what you have to do is multiply that number by 1000, do the round function and then divide by 1000
  5. Apr 29, 2004 #4
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook