在Android中将十进制舍入为1.00和0.10

时间:2017-04-08 02:28:27

标签: android decimal rounding

作为标题,如果数字为1.01,1.02,1.03,1.04,如何将十进制数舍入为1.00,如果数字为0.05,0.06,0.07,0.08,0.09,则将小数点数舍入为0.10

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

 private static void roundOff(double num) {
    double intPart = (int) num;
    double rondededOffNum = intPart+ Math.round((num- intPart)*10)/10.0;
    System.out.println(rondededOffNum);
}