Hello, Here in canada we decided to remove the penny(1 cents)...HURRAY

Anyway so now all transaction must be rounded up or down (lets say for now just round up) to either

ex. 25.24 rounded up will become 25.25

ex. 14.27 rounded up will become 14.30

ex. 15.22 round up will become 15.25

can anyone help me with this..Im having a hard time doing the math logic to get this result.

any help will be good..thanks

# Help..rounding up the penny canada

Page 1 of 1## 6 Replies - 1796 Views - Last Post: 07 March 2013 - 07:43 PM

##
**Replies To:** Help..rounding up the penny canada

### #2

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 10:56 AM

have a look at the Round function, should do what you want.

I just re-read your post, and I think my suggestion won't work, as I misunderstood it a little. You're working out for currency, hence rounding to the nearest coinage value.

I just re-read your post, and I think my suggestion won't work, as I misunderstood it a little. You're working out for currency, hence rounding to the nearest coinage value.

This post has been edited by **maj3091**: 07 March 2013 - 11:01 AM

### #3

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 10:57 AM

... you just round to the nearest larger 5 cent area. If anything you can drolly do it by a for loop. Given your current cents check if the number mod 5 is 0.. if so then you don't need to round. If it doesn't then increment your number, checking after each increment if the current number mod five is zero. Stop when you do.

### #4

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 10:58 AM

Hey.

Assuming we have the cent count as x, I suppose the algorithm could look like:

That is, if the remainder of x divided by 5 is not 0, then add 5 minus said remainder to x, to make it dividable by 5 again.

So:

See what I mean?

Assuming we have the cent count as x, I suppose the algorithm could look like:

IF x % 5 != 0: x += 5 - (x % 5)

That is, if the remainder of x divided by 5 is not 0, then add 5 minus said remainder to x, to make it dividable by 5 again.

So:

24 + (5 - 4) == 25 27 + (5 - 2) == 30 22 + (5 - 2) == 25

See what I mean?

### #5

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 10:59 AM

thanks for all the reply

### #6

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 11:12 AM

Atli, on 07 March 2013 - 05:58 PM, said:

Hey.

Assuming we have the cent count as x, I suppose the algorithm could look like:

That is, if the remainder of x divided by 5 is not 0, then add 5 minus said remainder to x, to make it dividable by 5 again.

So:

See what I mean?

Assuming we have the cent count as x, I suppose the algorithm could look like:

IF x % 5 != 0: x += 5 - (x % 5)

That is, if the remainder of x divided by 5 is not 0, then add 5 minus said remainder to x, to make it dividable by 5 again.

So:

24 + (5 - 4) == 25 27 + (5 - 2) == 30 22 + (5 - 2) == 25

See what I mean?

Boy was I over thinking this one..... time to rest my head....

### #7

## Re: Help..rounding up the penny canada

Posted 07 March 2013 - 07:43 PM

Or in VB with one line: (x * 100 - Iif(x * 100 mod 5 = 0, 0, x * 100 mod 5 + 5)) / 100 will round x up to the next nickel.

Of course, the OP was probably trying to simplify by saying to start with always rounding up. It's much simpler to round to the nearest nickel using the round function, so:

Round(x / 5, 2) * 5

This will round the way you want, jrwebguy. (By the way, if you had googled "round to nearest 5" you would have found this right away.)

Of course, the OP was probably trying to simplify by saying to start with always rounding up. It's much simpler to round to the nearest nickel using the round function, so:

Round(x / 5, 2) * 5

This will round the way you want, jrwebguy. (By the way, if you had googled "round to nearest 5" you would have found this right away.)

This post has been edited by **BobRodes**: 07 March 2013 - 08:06 PM

Page 1 of 1