在Excel中按特定小数值四舍五入一个数字。

huangapple go评论73阅读模式
英文:

Round a number by specific decimal value in excel

问题

我正在尝试对一个带有特定条件的小数进行四舍五入。如果第一个小数点大于或等于9,则向上舍入,否则向下舍入。需要帮助。

100.123 -> 100
100.8 -> 100
100.9999 -> 101
100.9001 -> 101

我知道在Excel中有rounduprounddown函数,但它们是基于小数值是否大于或等于5来进行四舍五入或舍去的逻辑。

英文:

I am trying to round a decimal number with certain condition. If first decimal point is greater than or equal to 9 then round up else round down. Need help in this.

100.123 -> 100
100.8 -> 100
100.9999 -> 101
100.9001 -> 101

I am aware of roundup and rounddown functions in excel, but that works based on logic that if decimal value is greater than or equal to 5 then round up else round down.

答案1

得分: 3

IF "E5" 是十进制数:

=IF(NUMBERVALUE(LEFT(RIGHT(E5;FIND(".";E5)-1);1))>=9;ROUNDUP(E5;0);ROUNDDOWN(E5;0))

英文:

IF "E5" is the decimal number:

=IF(NUMBERVALUE(LEFT(RIGHT(E5;FIND(".";E5)-1);1))>=9;ROUNDUP(E5;0);ROUNDDOWN(E5;0))

答案2

得分: 3

以下是要翻译的内容:

这是我的提案。它与Toby的提案非常相似,但我将数字视为数字,而不是文本:

=IF(A1-ROUNDDOWN(A1,0)>=0.8,ROUNDUP(A1,0),ROUNDDOWN(A1,0))

它产生以下结果:

英文:

Hereby my proposal. It's very similar to the one from Toby, but I treat numbers as numbers, not as text:

=IF(A1-ROUNDDOWN(A1,0)>=0.8,ROUNDUP(A1,0),ROUNDDOWN(A1,0))

It gives following results:

在Excel中按特定小数值四舍五入一个数字。

答案3

得分: 3

Another option:

=INT(A1)+(MOD(A1,1)>=0.9)

英文:

Another option:

=INT(A1)+(MOD(A1,1)>=0.9)

在Excel中按特定小数值四舍五入一个数字。

huangapple
  • 本文由 发表于 2023年5月25日 16:55:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定