6 Replies - 1368 Views - Last Post: 07 March 2013 - 07:43 PM Rate Topic: -----

#1 jrwebguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-March 13

Help..rounding up the penny canada

Posted 07 March 2013 - 10:51 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Help..rounding up the penny canada

#2 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

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.

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

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,430
  • Joined: 12-June 08

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.
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

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:
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?
Was This Post Helpful? 1
  • +
  • -

#5 jrwebguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-March 13

Re: Help..rounding up the penny canada

Posted 07 March 2013 - 10:59 AM

thanks for all the reply
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Help..rounding up the penny canada

Posted 07 March 2013 - 11:12 AM

View PostAtli, on 07 March 2013 - 05:58 PM, said:

Hey.

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....
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

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

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1