Can someone explain to me, why this happens?
var float:Number = 1.40;
var bytes:ByteArray = new ByteArray();
trace('float: ' + float);
bytes.writeFloat( float );
bytes.position = 0;
trace('bytes.readFloat: ' + bytes.readFloat() );
Output from trace:
>> float: 1.4
>> bytes.readFloat: 1.399999976158142
this driving me crazy in the last hours.
Thanks
ByteArray.writeFloat()writes only 4 bytes, meaning a single precision flosting-point value gets stored. You have to callwriteDouble()to write your float, and even then you might lose precision, although that loss won’t be as drastical. This is the core limitation of floating point types.