aryx
-
Total Posts
:
10
- Scores: 0
-
Reward points
:
0
- Joined: 10/20/2005
-
Status: offline
|
Sum not matching?
Monday, January 30, 2012 3:08 AM
( permalink)
I'm trying to add some numbers together and it should end up beeing zero. But instead I get -9,094... It seems to be the decimals that is the cause, why is this happening and how can I solve it? strTotSum=-12698.2
strTotCash=5016
strTotWeb=2265
strTotCheque=0
strTotCard=5417.2
msgbox strTotSum + strTotCash + strTotWeb + strTotCheque + strTotCard
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Sum not matching?
Monday, January 30, 2012 3:15 AM
( permalink)
Actually the result that you are getting is .000000000000909494701772928 This has to do with the way that vbs handles non-integers. If for instance you are doing financial calculations (so the decimal will at most be hundredths) then I would do it like this: strTotSum=-12698.2 * 100 strTotCash=5016 * 100 strTotWeb=2265 * 100 strTotCheque=0 * 100 strTotCard=5417.2 * 100 wscript.echo (strTotSum + strTotCash + strTotWeb + strTotCheque + strTotCard)/100
|
|
|
|
aryx
-
Total Posts
:
10
- Scores: 0
-
Reward points
:
0
- Joined: 10/20/2005
-
Status: offline
|
Re:Sum not matching?
Monday, January 30, 2012 4:03 AM
( permalink)
Great, thanks for the solution!
|
|
|
|