Double value to round up in Java

后端 未结 10 1933
我寻月下人不归
我寻月下人不归 2020-12-07 12:44

I have a double value = 1.068879335 i want to round it up with only two decimal values like 1.07.

I tried like this

DecimalFormat df=new         


        
10条回答
  •  醉话见心
    2020-12-07 13:26

    You could try defining a new DecimalFormat and using it as a Double result to a new double variable.

    Example given to make you understand what I just said.

    double decimalnumber = 100.2397;
    DecimalFormat dnf = new DecimalFormat( "#,###,###,##0.00" );
    double roundednumber = new Double(dnf.format(decimalnumber)).doubleValue();
    

提交回复
热议问题