0

This has been asked before, but the answers are years out of date (a decade in some cases).

If I have a double value and want to round it to 2 decimal places (eg, 200.3456 to 200.35), what is the best method to do it in Java 12 and 13? Some of the numbers I'm using have whole number parts in the tens-of-thousands range (eg, 95,000.00).

For the sake of completeness, does the method make any difference if I only want to print the result as text?

CMB
  • 133
  • 4
  • 1
    Also https://stackoverflow.com/q/153724/14955. I don't think Java 12/13 add anything in this area, and even the decade-old answers still work. – Thilo Sep 20 '19 at 09:36
  • rounding at the very end (as part of printing) vs rounding at every step of the calculation can make a big difference, yes. Business requirements may call for either method. – Thilo Sep 20 '19 at 09:39

0 Answers0