How do I format a number in Java?

前端 未结 9 1763
自闭症患者
自闭症患者 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:38

    You and String.format() will be new best friends!

    https://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax

     String.format("%.2f", (double)value);
    

提交回复
热议问题