-2

i have seen this following math method called:

Math.round(d*10000) / (double) 10000;

and i don't know what it means. can someone please explain me ? thank you

marstran
  • 26,413
  • 5
  • 61
  • 67
daniel
  • 9

1 Answers1

2

Assuming d is a double or float. It multiplies d with 10000. Rounds to the nearest whole number, and divides by 10000

If effect, it returns the original number with '4 digits as decimal fraction' (without resorting to formatting to String and parsing)

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
  • 1
    Sort of. Since a java double is an IEEE binary floating point type it cannot represent this result exactly. The notion of decimal "digits" can really only be effectively supported by a decimal type, which is `BigDecimal` in Java. – President James K. Polk Feb 06 '19 at 16:22
  • 1
    Correct. Although it cannot be exactly represented, it won't matter too much, unless the number is so large the least significant digits won't fit the mantissa. – Rob Audenaerde Feb 06 '19 at 20:36