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