Skip to content

Amount

subtract

1.0.0

Subtracts an amount from another amount.

amount.subtract(/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 subtract() method to subtract an Amount, number, or string value from 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 result = amount1.subtract(amount2).subtract(25);
console.log(result); // Results an Amount instance with value 25 USD

It handles negative results correctly:

const value = amount(5.25, 'USD');
const result = value.subtract(10.5); // Results -5.25 USD

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

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

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.