Use if statement against the ones place decimal value in Excel

泄露秘密 提交于 2019-12-25 02:17:14

问题


I need help creating a formula that rounds a number with a 1 or 6 in the ones place down to the nearest multiple of 5 (e.g., 276 to 275 or 131 to 130) and rounds any other number up to the nearest multiple of 5 (e.g., 277 to 280 or 132 to 135). I figured the logic would look something like this:

=if(can't figure out this condition, ceiling(A1,5), floor(A1,5))


回答1:


You can use MROUND instead:

=MROUND(A1,5)

It rounds to the nearest 5. Anything including and above 277.5 will be rounded to 280, and anything below that will be rounded to 275.

If you still want to use IF, then I would pick MOD:

=IF(MOD(A1,5)>2.5, CEILING(A1,5), FLOOR(A1,5))

So, if the remainder is above 2.5 when divided by 5, round up, otherwise, down.




回答2:


Try something like this:

=IF(OR(RIGHT(A1,1)="1",RIGHT(A1,1)="6"),FLOOR(A1,5),CEILING(A1,5)))

or little bit shorter:

=IF(ISNUMBER(FIND(RIGHT(A1,1),"16")),FLOOR(A1,5),CEILING(A1,5))


来源:https://stackoverflow.com/questions/23202513/use-if-statement-against-the-ones-place-decimal-value-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!