I want to perform simple calculation on two variables as
var a:String = "1.025";
var b:String = "1.022";
var c: String = ( a - b ) * 10000;
For some reason variable c now hold "29.999999999998916"
instead of 30.
I am using strings because that is what is returned from a
remote script via httpservice. I understand that Flex/Flash convert
any String to Number when used in an expression for calculation.
What is going on here?
Sadly from my knowledge that is just how AS3 does its
calculations... it always spits out a floating type, if you want to
fix this issue just do this
var c:String = Math.ceil( ( Number(a) - Number(b) ) * 10000
).toString(); You will get 30. the "ceil()" function rounds the