
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mongo-round
Advanced tools
Mongo Aggregation Framework helper function to perform rounding of numbers
Helper function to perform rounding of numbers when working with mongoDB Aggregation Framework.
npm install mongo-round
var round = require('mongo-round');
To zero decimal places:
db.myCollection.aggregate([
{ $project: {
roundValue: round('$value')
} }
]);
To two decimal places:
db.myCollection.aggregate([
{ $project: {
roundAmount: round('$amount', 2)
} }
]);
To cents and from cents - saves from rounding errors for armithmetic operations on financial data:
db.myCollection.aggregate([
{ $project: {
amountCents: round({$multiply:['$amount', 100]})
} },
{ $group: {
_id: null, amountCents: {$sum: '$amountCents'}
} }
{ $project: {
amount: round({$divide:['$amountCents', 100]}, 2)
} }
]);
Note that for negative numbers rounding is done using absolute values, which is fitting for financial data:
round(-0.5) will give -1
FAQs
Mongo Aggregation Framework helper function to perform rounding of numbers
The npm package mongo-round receives a total of 5,016 weekly downloads. As such, mongo-round popularity was classified as popular.
We found that mongo-round demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.