Results 1 to 6 of 6

Thread: Denomination Calc

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    16

    Denomination Calc

    Hi all,
    Probably a bit easy but I can't seem to get it to work. How do I go about calculating what denominations I need to make up a money total in VB? e.g. £12.35...how do I calculate that it would need 12 pound coins, 3 ten pence coins, and 1 five pence coin?
    I know it has something to do with mod and division, but I can't get it to work.
    Any help would be greatly appreciated,
    littlefitzer

  2. #2
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375
    You would use 12.35 div 1 to get the number of pound coins

    You would use 12.35 mod 1 to get the .35 left over

    Then repeat the mod/division process on the remaining money.
    -Show me on the doll where the music touched you.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    16

    Thanks...but..

    Thanks very much, but could you show me a brief code example as I keep getting compile errors when I use div?
    Thanks again.

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    use a "\" instead of "div". It's integer divison

    I checked on some stuff and found that "\" may not work with decimals, you can always do int(12.35/1) or whatever is nesscessary d
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    16

    thanks...

    Thanks for your help!!

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Use Single or Doubles to hold non integers.

    You could get the fractional part by
    Fraction = Amount - Int(Amount)

    Then Xvalue = Fraction * 10

    TenPenceCoins = Int(Xvalue)

    Then Xvalue = Int(Xvalue - TenPenceCoins)

    Use a long for OnePenceCoins

    Then OnePenceCoins = Xvalue*10

    FivePencecoins = OnePenceCoins \ 5 (Integer division).

    OnePenceCoins = FivePenceCoins Mod 5
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width