4 examples of 'javascript division round up' in JavaScript

Every line of 'javascript division round up' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
11function roundOne(decimalNumber) {
12 return roundTo(decimalNumber, 1);
13}
2527BN.prototype.divRound = function divRound (num) {
2528 var dm = this.divmod(num);
2529
2530 // Fast case - exact division
2531 if (dm.mod.isZero()) return dm.div;
2532
2533 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2534
2535 var half = num.ushrn(1);
2536 var r2 = num.andln(1);
2537 var cmp = mod.cmp(half);
2538
2539 // Round down
2540 if (cmp < 0 || (r2 === 1 && cmp === 0)) return dm.div;
2541
2542 // Round up
2543 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
2544};
61export function roundDown(
62 value: BigNumber.Value,
63 decimals: number = 2,
64 roundingTolerance: number = 0
65): BigNumber {
66 if (roundingTolerance) {
67 value = new BigNumber(value).decimalPlaces(
68 decimals + roundingTolerance,
69 BigNumber.ROUND_HALF_DOWN
70 )
71 }
72 return new BigNumber(value).decimalPlaces(decimals, BigNumber.ROUND_DOWN)
73}
4function round(v, n) {
5 return +(Math.round(v + 'e+' + n) + 'e-' + n);
6}

Related snippets