Ok, I'm writing a script that deals with money amounts. But, I want it to simply drop fractions of a cent. So, I wrote the following code:
Somehow, I lose a cent during Fix (or Int). Now, some interesting bits:
Fix(895) = 895
Fix(8.95 * 100) = 894
Fix(995) = 995
Fix(9.95 * 100) = 994
Any ideas on why it rounds the whole number down? From what I can tell I have a two options, hard code for values like 8.95 and 9.95 or multiply by 100.00000000001. The problem with the first option is, I'd need to find all the times when Fix rounds wrong. The problem with the second is it would round up for million dollar values with .91 fractions of a cent.
So, any work arounds are appreciated.
Code:
Amt = 8.95
WScript.Echo "Amt = " & Amt
Amt = Amt * 100
WScript.Echo "Amt * 100 = " & Amt
Amt = Fix(Amt)
WScript.Echo "Fix(Amt) = " & Amt
Amt = Amt / 100
WScript.Echo "Amt /100 = " & Amt
Amt = FormatNumber(Amt,2)
WScript.Echo "FormatNumber(Amt,2) = " & Amt
Somehow, I lose a cent during Fix (or Int). Now, some interesting bits:
Fix(895) = 895
Fix(8.95 * 100) = 894
Fix(995) = 995
Fix(9.95 * 100) = 994
Any ideas on why it rounds the whole number down? From what I can tell I have a two options, hard code for values like 8.95 and 9.95 or multiply by 100.00000000001. The problem with the first option is, I'd need to find all the times when Fix rounds wrong. The problem with the second is it would round up for million dollar values with .91 fractions of a cent.
So, any work arounds are appreciated.