Rounding problems with new NumberDecimal

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.3.14
    • Component/s: Aggregation Framework
    • None
    • Environment:
      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
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 }

            Assignee:
            Geert Bosch
            Reporter:
            Udo Held
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: