Formatting double to 2 decimals doesn't work

后端 未结 4 1249
旧时难觅i
旧时难觅i 2021-01-20 04:34

I want to round this double:

3.499999999999999

to:

3.50

And I already used these two methods:

<         


        
4条回答
  •  青春惊慌失措
    2021-01-20 05:08

    You can use the printf formatting which may be simpler.

    System.out.printf("%.2f%n", 3.5);
    

    prints

    3.50
    

提交回复
热议问题