You presumably meant the result should be 23.7, not 23.8. However, getting 23.700000000000003 isn't a bug; you'd get the
same answer in other languages like Java and C++. The imprecision is because Number
in ActionScript (like float in Java and C++) stores a floating-point value as a
binary fraction, not as a decimal fraction. These datatypes use binary fractions
because that's how current microprocessors store and manipulate floating-point
values. Java solves this problem by having a BigDecimal class whjich
can store decimal fractions. In that case, computations are slower because it
takes many microsprocessor instructions to do a single operation. The current version of ActionScript doesn't have any decimal
fraction datatype, but it is under consideration for a future version of the
language. The lack of this feaure comes up about once a week, and some participants
on flexcoders have discussed the possibiliy of porting BigDecimal or its
equivalent to ActionScript. Perhaps you can simply round your results to the precision
you need? Take a look at the toFixed() method of the Number class. - Gordon From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf
Of beloved_zhou I am using Flex2.0, and I try to get a result about 3
multiply 7.9, -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS
__,_._,___ |
- RE: [flexcoders] Is this a bug? About Number type. Gordon Smith
- [flexcoders] Re: Is this a bug? About Number type. beloved_zhou