Domanda

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))

È stato utile?

Soluzione

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.

Altri suggerimenti

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))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top