Re: [问题] 资料型态问题

楼主: cleanwind (C.Y.)   2014-05-15 05:39:10
是精度的问题。
AS3's Number type, like Java's or C++'s 'double' type, store floating-point
values using binary fractions, not decimal fractions, so there is some loss of
precision occuring. There is no fractional-decimal type in AS3.
I'll leave it to folks in the developer community working on financial
applications to explain how they work around this limitation.
Gordon Smith
Adobe Flex SDK Team
http://zengrong.net/post/1186.htm
解决方式或许可以采用 toFixed() ?
http://livedocs.adobe.com/flash/9.0_tw/ActionScriptLangRefV3/Number.html
※ 引述《pino0707 (威士登)》之铭言:
: var num:Number=0.7;
: var num2:Number=0.3;
: trace(num-num2)
: 会呈现0.399999997这种数字...
: 这是什么原因呢?
作者: KawasumiMai (さあ、死ぬがいい)   2014-05-15 15:08:00
印象中以前也有上过0.999999999的课不过忘记原因了QQ
楼主: cleanwind (C.Y.)   2014-05-15 20:02:00
因为二进制在处理小数点的部分会有误差

Links booklink

Contact Us: admin [ a t ] ucptt.com