Search code examples
excelgoogle-sheetsgoogle-sheets-formulaformula

How to round to nearest 0, 5 or 9 integer


How to round a given number to a 0, 5 or 9, which ever is closest? I've tried with:

=MROUND(I2,5)-((MOD(MROUND(I2,5),10))=0)

But I need zeros too, this only gives me fives and nines. Thanks


Solution

  • =1*(ROUNDDOWN(A2/10,0)&INDEX({0,5,9},MATCH(MIN(ABS({0,5,9}-MOD(A2,10))),ABS({0,5,9}-MOD(A2,10)),0)))
    
    • MOD to get right digit of cell
    • Find the distance between {0,5,9} and the right digit and MATCH it to the closest digit
    • Concatenate right of the matched digit to the left digit and multiply by 1

    Added a 0 to ROUNDDOWN to satisfy , producing the following:
    here
    plot