msgpack / msgpack-node

MessagePack implementation for Node.js
Other
311 stars 72 forks source link

Decode incorrect value - {"1":0.12} #41

Closed JohnRSim closed 6 years ago

JohnRSim commented 6 years ago

when I encode and then decode I'm not getting expected output..

let a = encode  = msgpack.encode,
    decode  = msgpack.decode;

const encodePack = encode({"1":0.12});
console.log(decode(encodePack));
//{ '1': 0.11999999731779099 }

Output - { '1': 0.11999999731779099 }

Expected - {"1":0.12}

llint commented 6 years ago

This is floating point precision issue - because 0.12 cannot be precisely represented in the IEEE754 format - thus it's represented as the value as you see.

this is not a bug.