Amount
negate
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Returns the negated value of an amount, flipping the sign from positive to negative or vice versa.
amount.negate();Features
Section titled “Features”- Returns a new
Amountinstance 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
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
| 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 USDconsole.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 EURIt 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 USDBuilt with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.