简体   繁体   English

如何将单元格中的数字四舍五入到 Excel 中的特定数字

[英]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.

相关问题 如何检查Excel中的单元格是否包含超过特定值的数字? - How can I check if a cell in Excel contains a number over a specific value? Excel是否自动将数字四舍五入? - Does Excel round up a number automatically? 如何检查Excel电子表格中的单元格是否包含数字 - How can I check if a cell in Excel spreadsheet contains number 在Excel中,如何计算特定情况发生的次数? - In Excel, how can I count the number of times a specific situation occurs? 如何在Excel中计算具有不同颜色的特定形状的数量 - How can I count the number of specific shapes with different color in excel 如何更改excel轮次的十进制数(默认值为.50,我需要它在.20左右向上或向下舍入,不管十进制数之前的数字) - How to change the decimal in which excel rounds (Default is .50, I need it to round up or down at .20 regarudless of the number preceding the decimal) 如何将我在excel单元格中输入的值乘以常数,结果出现在同一单元格上? - How can multiply a value I enter in an excel cell by a constant number, with result on appearing on same cell? 如何将负数连续向上移动一个单元格并转换为正数,然后删除负数行? - How can I move a negative number in a row up one cell and convert to a positive number, then delete negative number row? 四舍五入到特定的乘法 - Round number to specific multiply 在 Excel 中,如何四舍五入到最接近的斐波那契数 - In Excel, how to round to nearest fibonacci number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM