Skip to content

Amount

abs

1.0.0

Returns the absolute value of an amount, removing any negative sign.

amount.abs();
  • Returns a new Amount instance with absolute value
  • Preserves the original currency
  • Maintains immutability - original instance remains unchanged
  • Handles both positive and negative values
  • Simple and intuitive API
  • Comprehensive testing
ArgTypeDefault ValueRequired
No arguments required

From an Amount instance, use the abs() method to get the absolute value of the amount.

import { amount } from '@inpulse-ui/utils';
const negativeAmount = amount(-100.50, 'USD');
const result = negativeAmount.abs();
console.log(result); // Results in Amount instance with value 100.50 USD
console.log(negativeAmount); // Original remains -100.50 USD (immutable)

It works with positive values as well (returns the same value):

const positiveAmount = amount(75.25, 'EUR');
const result = positiveAmount.abs();
console.log(result); // Results in Amount instance with value 75.25 EUR

It handles zero values correctly:

const zeroAmount = amount(0, 'GBP');
const result = zeroAmount.abs();
console.log(result); // Results in Amount instance with value 0 GBP

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.