简体   繁体   中英

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
  2. if 01 to 49, then round up to 50
  3. if 51 to 98, then round up to 99

examples:

  • if the number is 1251, then it's 1299
  • if the number is 1298, then it's 1299
  • if the number is 4874, then it's 4899
  • if the number is 1433, then it's 1450
  • if the number is 1880, then it's 1899
  • if the number is 1301, then it's 1350
  • if the number is 1200, then it's 1299
  • if the number is 1250, then it's 1250 (unchanged)
  • if the number is 1299, then it's 1299 (unchanged)

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

假设值在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):

=(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
  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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