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