Skip to content

Amount

isEqualTo

1.0.0

Checks if an amount is equal to another amount by comparing both the cents value and currency. This method has an alias named equals() for convenience.

amount.isEqualTo(/amount/);
// or using the alias
amount.equals(/amount/);
  • Returns a boolean value indicating if amounts are equal
  • Compares both cents value and currency for exact equality
  • Requires both amounts to have the same currency
  • Has a convenient equals() alias method
  • Simple and intuitive API
  • No side effects - read-only operation
  • Comprehensive testing
ArgTypeDefault ValueRequired
amountAmount-Yes

From an Amount instance, use the isEqualTo() method to check if it equals another amount.

import { amount } from '@inpulse-ui/utils';
const amount1 = amount(100, 'USD');
const amount2 = amount(100, 'USD');
const result = amount1.isEqualTo(amount2);
console.log(result); // true

Using the equals() alias:

const amount1 = amount(50.75, 'EUR');
const amount2 = amount(50.75, 'EUR');
console.log(amount1.equals(amount2)); // true - same as isEqualTo()

It returns false for different values:

const amount1 = amount(100, 'USD');
const amount2 = amount(50, 'USD');
console.log(amount1.isEqualTo(amount2)); // false
console.log(amount1.equals(amount2)); // false

It returns false for different currencies:

const amount1 = amount(100, 'USD');
const amount2 = amount(100, 'EUR'); // Same value, different currency
console.log(amount1.isEqualTo(amount2)); // false

Useful for conditional logic:

const expectedPayment = amount(250.00, 'USD');
const receivedPayment = amount(250.00, 'USD');
if (receivedPayment.equals(expectedPayment)) {
console.log('Payment received in full');
} else {
console.log('Payment amount mismatch');
}
// Output: "Payment received in full"

Validation in business logic:

const orderTotal = amount(99.99, 'USD');
const paymentAmount = amount(99.99, 'USD');
if (paymentAmount.isEqualTo(orderTotal)) {
console.log('Processing order...');
// Proceed with order processing
} else {
console.log('Payment amount does not match order total');
}
// Output: "Processing order..."

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.