In mongodb, the sum of $sum decimals is an integer, and all the numbers after the decimal point are forcibly removed.

the data in the database is like this. There are decimals, and I need to sum them.

execute the following code:

bet.aggregate(
  {
    $match: {
      state: { $in: [0, 1, 2, 3] }
    }
  },
  {
    $group: {
      _id: { state: "$state" },
      serviceCharge: { $sum:  "$serviceCharge" },
      percentage: { $sum: "$percentage" },
      income:{ $sum: { $subtract: [ "$serviceCharge","$percentage"] } }
    },
  },
  { $project: { "_id": 0, "state": "$_id.state", "serviceCharge": 1, "percentage": 1 ,"income":1} },
  (err, ret) => {
    console.log(ret)
  })
The result of

is:
[
{serviceCharge: 6, percentage: 0, income: 6, state: 2},
{serviceCharge: 57, percentage: 38, income: 19, state: 0}
]
Why is the result an integer? Solve!

Mar.04,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3319d-34233.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3319d-34233.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?