Vat Trace

by Jimmy on August 2, 2008

vat trace
Actionscript 3 irritating math issue?

Why do I get 2 different results for working the vat out in actionscript 3.0? I just spent about 3 hours working out why my calculations where incorrect and this was the reason:

var res1:Number = 17.4*0.175;
trace("res1:"+res1);

var res2:Number = (17.4/100)*17.5;
trace("res2:"+res2);

//RESULTS

res1:3.0449999999999995
res2:3.045

I just can't understand why the first result is different. Does anyone know why?

This baffed me esp when I did it in excel. However - it's because in the res1 - 175 is /100 and in the second 17.4/100.

So

var res1:Number = 17.4*0.175;
trace("res1:"+res1);

var res2:Number = (17.4)*(17.5/100);
trace("res2:"+res2);

Give the first result: (3.0449999999999995) twice and

var res1:Number = 0.174*17.5;
trace("res1:"+res1);

var res2:Number = (17.4/100)*17.5;
trace("res2:"+res2);

Gives the second result (3.045) twice

XA-VAT - EPOC TRACE


No items matching your keywords were found.
We did not find any matches for your request.

Leave a Comment

Previous post:

Next post: