开发者

Number data type automatically loses precision in Flex

private function getPercentage(max:Number, value:Number):int
{
   return Number((value*100) / max);
}

I call开发者_如何学编程 the above function to assign a percentage to an object.

var max:Number = findMax();
p.percentage = getPercentage(max, p.value);

Assume that p is some object with percentage defined as

public var percentage:Number;

When I put a breakpoint and check for the value returned in getPercentage it will something like 1.22343342322 but when I assign it to p.percentage it automatically becomes 1, losing the precision.

How do I handle this kind of a situation?

It says in the LiveDocs

To store a floating-point number, include a decimal point in the number. If you omit a decimal point, the number will be stored as an integer.

But how do I do that? Any insight to this problem is highly appreciated.


Your method getPercentage() returns int. Change it to Number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜