js:6 + 0.55 = 6.549999999999999 mongodb: 6 $inc 0.55 ,也会变成 6.549999999999999 怎么办啊? 会导致金额乱糟糟的。
$ mongo test MongoDB shell version: 3.2.10 connecting to: test > > db.test.insertOne({ x: 0.1 }) { "acknowledged" : true, "insertedId" : ObjectId("588a3f711554cc7d70642fa1") } > db.test.updateOne({}, { $inc: { x: 0.2 } }) { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 } > db.test.findOne() { "_id" : ObjectId("588a3f711554cc7d70642fa1"), "x" : 0.30000000000000004 } >
$ node > 0.1 0.1 > 0.2 0.2 > 0.1 * 0.2 0.020000000000000004 > 0.1 * 0.1 0.010000000000000002 >
https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-decimal.html
http://adripofjavascript.com/blog/drips/avoiding-problems-with-decimal-math-in-javascript.html
IEEE 764
@waitingsong 你们是怎么解决呢?
@yhj8899 我这边数据库都是存的整数,用的时候除以100
bignumber.js
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-decimal.html
http://adripofjavascript.com/blog/drips/avoiding-problems-with-decimal-math-in-javascript.html
IEEE 764
@waitingsong 你们是怎么解决呢?
@yhj8899 我这边数据库都是存的整数,用的时候除以100
bignumber.js