Skip to content

Amount

negate

1.0.0

Returns the negated value of an amount, flipping the sign from positive to negative or vice versa.

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

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

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

It works with negative values as well (makes them positive):

const negativeAmount = amount(-75.25, 'EUR');
const result = negativeAmount.negate();
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.negate();
console.log(result); // Results in Amount instance with value 0 GBP (zero remains zero)

You can chain multiple operations:

const value = amount(50, 'USD');
const result = value.negate().abs(); // First negate (-50), then absolute value (50)
console.log(result); // Results in Amount instance with value 50 USD

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.