/ Published in: ActionScript 3

This seems to be a bug.. or not..
But explains how to fix it anyway.
But explains how to fix it anyway.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var a:Number = 0.99; var s:String = String(a);trace(s); // 0.99 s = String(a/100); trace(s); // 0.009899999999999999 // 8 ? var p:String = "0.99"; trace(Number(p)/100); // 0.009899999999999999 // 8 ? trace(Number(p)); // 0.99 trace(Number(String(Number(p)/100))*100); // 0.9900000000000001 // 1 ? trace( Number(Number(p).toPrecision(8))/100 ); // 0.009899999999999999 // fix - as I need the first 2 decimals... problem is solved trace((Number(p)/100).toPrecision(8)) // 0.0099000000 var f:String = (Number(p)/100).toPrecision(8); // seems fixed var fs:Number = Number(f); trace(fs); // 0.0099 // but also trace(fs*100); // 0.9900000000000001
Comments
