How do I format a number in Java?

前端 未结 9 1768
自闭症患者
自闭症患者 2020-11-22 05:10

How do I format a number in Java?
What are the "Best Practices"?

Will I need to round a number before I format it?

32.302342

9条回答
  •  一生所求
    2020-11-22 05:29

    There are two approaches in the standard library. One is to use java.text.DecimalFormat. The other more cryptic methods (String.format, PrintStream.printf, etc) based around java.util.Formatter should keep C programmers happy(ish).

提交回复
热议问题