Skip to content

Amount

add

1.0.0

Adds an amount to another amount.

amount.add(/amount/);
  • Returns a single Amount as result
  • Accepts mixed parameter types
  • Automatically inherits currency from the current Amount instance
  • Maintains type safety with proper error handling for currency mismatches
  • Simple and intuitive API
  • Comprehensive testing
ArgTypeDefault ValueRequired
amountAmount | number | string-Yes

From an initial Amount instance, use the add() method to add an Amount, number, or string value to it.

import { amount } from '@inpulse-ui/utils';
const amount1 = amount(100.00, 'USD');
const amount2 = amount('50.00', 'USD'); // You can also use string values
const amount3 = amount(25); // Inherits the current currency when not provided
const result = amount1.add(amount2).add(amount3).add(50).add('25');
console.log(result); // Results an Amount instance with value 250 USD

It handles negative values correctly:

const value = amount(10.50, 'USD');
const result = value.add(-5.25); // Subtracts 5.25 from 10.50 USD

It will throw an error if you try to add an amount with a different currency:

const value = amount(100, 'USD');
const result = value.add(50, 'EUR'); // Currency mismatch: USD vs EUR

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.