Formatting double to 2 decimals doesn't work

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

    Did you try replacing the 0's with #'s?

    DecimalFormat df = new DecimalFormat("#.##"); System.out.println(df.format(input));

    According to here the # will be resolved to 0 if the digit is absent

提交回复
热议问题