Skip to content

Amount

round

1.0.0

Rounds an amount using banker’s rounding (round half to even), which rounds .5 cases to the nearest even integer.

amount.round();
  • Returns a new Amount instance 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
ArgTypeDefault ValueRequired
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 USD
console.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 EUR
console.log(value2.round()); // 4 EUR
console.log(value3.round()); // 4 EUR
console.log(value4.round()); // 6 EUR

Standard rounding for non-.5 cases:

const value1 = amount(2.3, 'GBP');
const value2 = amount(2.7, 'GBP');
console.log(value1.round()); // 2 GBP
console.log(value2.round()); // 3 GBP

Works 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 CAD
console.log(negativeValue2.round()); // -4 CAD

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.