Amount
round
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Rounds an amount using banker’s rounding (round half to even), which rounds .5 cases to the nearest even integer.
amount.round();Features
Section titled “Features”- Returns a new
Amountinstance with rounded value - Preserves the original currency
- Maintains immutability - original instance remains unchanged
- Uses banker’s rounding (round half to even) for .5 cases
- Reduces bias in statistical calculations
- Simple and intuitive API
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
| No arguments required | |||
From an Amount instance, use the round() method to round the amount to the nearest integer using banker’s rounding.
import { amount } from '@inpulse-ui/utils';
const preciseAmount = amount(100.3, 'USD');const result = preciseAmount.round();
console.log(result); // Results in Amount instance with value 100 USDconsole.log(preciseAmount); // Original remains 100.3 USD (immutable)Banker’s rounding for .5 cases - rounds to nearest even:
const value1 = amount(2.5, 'EUR'); // Rounds to 2 (even)const value2 = amount(3.5, 'EUR'); // Rounds to 4 (even)const value3 = amount(4.5, 'EUR'); // Rounds to 4 (even)const value4 = amount(5.5, 'EUR'); // Rounds to 6 (even)
console.log(value1.round()); // 2 EURconsole.log(value2.round()); // 4 EURconsole.log(value3.round()); // 4 EURconsole.log(value4.round()); // 6 EURStandard rounding for non-.5 cases:
const value1 = amount(2.3, 'GBP');const value2 = amount(2.7, 'GBP');
console.log(value1.round()); // 2 GBPconsole.log(value2.round()); // 3 GBPWorks with negative values:
const negativeValue1 = amount(-2.5, 'CAD'); // Rounds to -2 (even)const negativeValue2 = amount(-3.5, 'CAD'); // Rounds to -4 (even)
console.log(negativeValue1.round()); // -2 CADconsole.log(negativeValue2.round()); // -4 CADBuilt with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.