Formatting double to 2 decimals doesn't work

后端 未结 4 1234
旧时难觅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:16

    You can use Precision class of apache commons-math

    double result = Precision.round(3.499999999999999, 2);
    

提交回复
热议问题