简体   繁体   English

在Excel公式中的复杂条件下四舍五入数字

[英]Rounding numbers in complex conditions in Excel formula

I need to round up/down the numbers (last 2 digits, no decimal) based on three conditions: 我需要根据以下三种情况对数字进行四舍五入(最后两位数字,无小数点):

  1. if 00, then -1 如果00,则-1
  2. if 01 to 49, then round up to 50 如果是01到49,则四舍五入到50
  3. if 51 to 98, then round up to 99 如果51到98,则四舍五入到99

examples: 例子:

  • if the number is 1251, then it's 1299 如果数字为1251,则为1299
  • if the number is 1298, then it's 1299 如果数字是1298,则是1299
  • if the number is 4874, then it's 4899 如果数字为4874,则为4899
  • if the number is 1433, then it's 1450 如果数字为1433,则为1450
  • if the number is 1880, then it's 1899 如果数字是1880,则是1899
  • if the number is 1301, then it's 1350 如果数字为1301,则为1350
  • if the number is 1200, then it's 1299 如果数字为1200,则为1299
  • if the number is 1250, then it's 1250 (unchanged) 如果数字为1250,则为1250(未更改)
  • if the number is 1299, then it's 1299 (unchanged) 如果数字为1299,则为1299(未更改)

.................. ..................

假设值在a1中

=IF(MOD(A1,100)=0,A1-1,IF(MOD(A1,100)<51,A1+50-MOD(A1,100),A1+99-MOD(A1,100)))

Try this. 尝试这个。 (Its quite nice apart from the fudge at the end for the 0 case): (除了结尾为0的情况下的软糖之外,这非常不错):

=(CEILING(A1/50,1)*50)-IF(MOD(FLOOR((A1-1)/50,1),2)=1,1,0)

In explanation: 在解释中:

  1. (CEILING(A1/50,1)*50) rounds up to the next 50 (CEILING(A1 / 50,1)* 50)向上舍入到下一个50
  2. IF(MOD(FLOOR(A1/50,1),2)=1,1,0) takes off 1 if the number is large than an odd multiple of 50 如果数字大于50的奇数倍,则IF(MOD(FLOOR(A1 / 50,1),2)= 1,1,0)取1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM