excel中的舍入功能

时间:2015-12-02 03:04:25

标签: excel-formula

议程:我想以下列格式整理整数(数字)

    If (LastDigitOfNumber=0)
    {
        Result=Number;
    }
    Else If (1<=LastDigitOfNumber<=3)
    {
        Result=Round down to nearest 10;
    }
    Else If (4<=LastDigitOfNumber<=6)
    {
          Result= Number as a multiple of 5;
          // for ex: if the number is 34, result=35
          // if number is 36, result=35
    }
    Else If (7<=LastDigitOfNumber<=9)
    {
          Result= Number rounded up to the nearest multiple of 10;
    }

问题:我不知道如何使用excel实现这一点,如果excel中的函数或舍入函数似乎不起作用。有人可以帮忙吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

试试这个公式:

=IF(MOD(A1,10)=0,A1,
  IF(AND(MOD(A1,10)>=1, MOD(A1,10)<=3), FLOOR(A1/10,1)*10,
    IF(AND(MOD(A1,10)>=4, MOD(A1,10)<=6), FLOOR(A1/10,1)*10+5,
      IF(AND(MOD(A1,10)>=7, MOD(A1,10)<=9), CEILING(A1/10,1)*10,"X")
    )
  )
)

结果

A1=10  --> 10
A1=11  --> 10
A1=12  --> 10
A1=13  --> 10
A1=14  --> 15
A1=15  --> 15
A1=16  --> 15
A1=17  --> 20
A1=18  --> 20
A1=19  --> 20
A1=20  --> 20

答案 1 :(得分:0)

这适用于上述问题,

= IF(MOD(E5,10)= 0,E5,E5 + CHOOSE(MOD(E5,10), - 1,-2,-3,1,0,-1,3,2,1, 0))

E5是电子表格中的单元格编号。