Search code examples
if-statementgoogle-sheetsgoogle-sheets-formularoundingnested-if

How to round to a speicific number


I assume this may be an easy task, I have tried searching in the community, but can't find the one which I am looking for, so i have some numbers and want to round to a specific number,

BEFORE AFTER ROUNDED
431 435
432 435
433 435
434 435
435 435
430 429
436 439
437 439
438 439
439 439
440 439

So, if the last digit is between 1-5 it will be i.e. 432 becomes 435; while 437 becomes 439. Also a sample data shown above, i have tried using MROUND or FLOOR Function but not getting through it, any way to get around this


Solution

  • try:

    =ARRAYFORMULA(
     IF(REGEXMATCH(INT(X9:X14)&""; ".+[1-5]$"); REGEXEXTRACT(INT(X9:X14)&""; "(.*)\d$")&5; 
     IF(REGEXMATCH(INT(X9:X14)&""; ".+[0]$"); INT(X9:X14)-1; REGEXEXTRACT(INT(X9:X14)&""; "(.*)\d$")&9))*1)
    

    enter image description here