Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-26364

Rounding problems with new NumberDecimal

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 3.3.14
    • Aggregation Framework
    • None
    • Windows 10
    • ALL
    • Hide

      db.fruitsd.drop()
      db.fruits.drop()
       
      db.fruitsd.insert( {_id: 3, item: "Plums",   price: 6.95, quantity: 7, type : "sweet"  } )
      db.fruitsd.insert( {_id: 4, item: "Peaches", price: NumberDecimal("7.49"), quantity: 12, type : "sweet" } )
      db.fruitsd.insert( {_id: 5, item: "Bananas", price: NumberDecimal("2.99"), quantity: 5, type : "sweet" } )
       
      db.fruits.insert( {_id: 3, item: "Plums",   price: 6.95, quantity: 7, type : "sweet"  } )
      db.fruits.insert( {_id: 4, item: "Peaches", price: 7.49, quantity: 12, type : "sweet" } )
      db.fruits.insert( {_id: 5, item: "Bananas", price: 2.99, quantity: 5, type : "sweet" } )
       
       
      db.fruitsd.aggregate([
        {
          $group: {
      	  _id: "$type",
      	  totalAmount: { $sum: "$price" },
      	  count: { $sum: 1 }
      	}
        }
      ])
       
      db.fruits.aggregate([
        {
          $group: {
      	  _id: "$type",
      	  totalAmount: { $sum: "$price" },
      	  count: { $sum: 1 }
      	}
        }
      ])
      

      Show
      db.fruitsd.drop() db.fruits.drop()   db.fruitsd.insert( {_id: 3, item: "Plums", price: 6.95, quantity: 7, type : "sweet" } ) db.fruitsd.insert( {_id: 4, item: "Peaches", price: NumberDecimal("7.49"), quantity: 12, type : "sweet" } ) db.fruitsd.insert( {_id: 5, item: "Bananas", price: NumberDecimal("2.99"), quantity: 5, type : "sweet" } )   db.fruits.insert( {_id: 3, item: "Plums", price: 6.95, quantity: 7, type : "sweet" } ) db.fruits.insert( {_id: 4, item: "Peaches", price: 7.49, quantity: 12, type : "sweet" } ) db.fruits.insert( {_id: 5, item: "Bananas", price: 2.99, quantity: 5, type : "sweet" } )     db.fruitsd.aggregate([ { $group: { _id: "$type", totalAmount: { $sum: "$price" }, count: { $sum: 1 } } } ])   db.fruits.aggregate([ { $group: { _id: "$type", totalAmount: { $sum: "$price" }, count: { $sum: 1 } } } ])
    • Integration 2016-10-10

    Description

      When doing rounding of double numbers together with the new NumberDecimal strange rounding problems show up. I'd expect a mix should return the same results as doubles only or NumberDecimals only.

      Mixed output from example:

      { "_id" : "sweet", "totalAmount" : NumberDecimal("17.43000000000000017763568394002505"), "count" : 3 }

      Output from doubles only:

      { "_id" : "sweet", "totalAmount" : 17.43, "count" : 3 }

      Attachments

        Activity

          People

            geert.bosch@mongodb.com Geert Bosch
            udoheld Udo Held
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: