I have a collection of products in MongoDB. An application running Express 3 and Mongoose. I am involved in auctions, and when I try to increase the price of a product by 0.01, it works fine up to the 6th time, then switches to "1000.0699999999999" instead of 1000.07. Any idea why? After a few clicks it will be: 1000.1699999999998, etc.
Here is my update function:
app.post('/auctions/add', function(req, res){
var user = req.session.username ;
var productID = req.body.product_id ;
Products.update( { id: productID }, {$inc: { price: .01 }, user_bidding: { username: user, timeBid: new Date() }}, function(err, numberAffected, raw) {
console.log(err);
console.log(numberAffected);
console.log(raw);
} ) ;
res.redirect( '/' );
}) ;
source
share