[英]How can I round up a number in cell to specific number in Excel
I have some product prices like我有一些产品价格,例如
30,56
25,34
26,88
30,13
I want to to round them with a 0,50 limit我想用 0,50 限制四舍五入
if the number is over x.50 to make it x.90 and if not make it x.50如果数字超过 x.50 则为 x.90,否则为 x.50
is it possible with a function of VBA?是否可以使用 VBA 的功能?
替代解决方案:
=INT(A1)+0.5+0.4*(MOD(A1,1)>0.5)
Use this formula to round:使用这个公式来四舍五入:
=IF(A:A-INT(A:A)>0.5,INT(A:A)+0.9,INT(A:A)+0.5)
Explanation解释
It subtracts the integer part of the floating number so and tests if this is >0.5
so A:A-INT(A:A)>0.5
means (30.56 - 30) > 0.5
which is 0.56 > 0.5
它减去浮点数的整数部分,然后测试它是否
>0.5
所以A:A-INT(A:A)>0.5
表示(30.56 - 30) > 0.5
,即0.56 > 0.5
The formula means something like that:这个公式的意思是这样的:
If (30.56 - 30) > 0.5 Then (30 + 0.9) Else (30 + 0.5)
Use IF, MOD and RoundDown使用 IF、MOD 和 RoundDown
=IF(MOD(A2,1)>0.5,ROUNDDOWN(A2,0)+0.9,ROUNDDOWN(A2,0)+0.5)
You may want additional conditions to handle fringe cases like a price of 0.您可能需要其他条件来处理边缘情况,例如价格为 0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.