简体   繁体   中英

Flex Number.toFixed not giving expected result

I have a function that gets a numeric value (as Object) and returns a well formatted representation of that number. Because we can get very small numbers, in the process we use the Number object of flex. this is part of the code:

var numericValue:Number = Number(value.toString());
var fixed:String = numericValue.toFixed(precision); 

This is the problem: there are situations that the numeric value is in the form of
5.684341886080802e-14 because we want to represent these numbers as 0 we use the above code. In this specific case, where precision is 0 we get an odd result

Initial Values:
value = 5.684341886080802e-14
percision = 0

Operation on values:
var numericValue:Number = Number(value.toString());
var fixed:String = numericValue.toFixed(precision); 

Result:
fix = "1."

Why is this?
(BTW - on other numbers in the representataion of X.XXXXXXe-YY with percision bigger than 0 we get the correct result of 0)

This is a bug in Flash Player ( FP-5141 ). It has been around for quite a while. The bug report says it is fixed, but it is not as of Flash Player 11.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM