Skip to content

Amount

isLessThanOrEqualTo

1.0.0

Checks if an amount is less than or equal to another amount by comparing their cents values. Both amounts must have the same currency.

amount.isLessThanOrEqualTo(/amount/);
  • Returns a boolean value indicating if the amount is less than or equal
  • Requires both amounts to have the same currency
  • Compares cents values for precise comparison
  • Returns true when amounts are equal
  • Throws error for currency mismatches
  • Simple and intuitive API
  • No side effects - read-only operation
  • Comprehensive testing
ArgTypeDefault ValueRequired
amountAmount-Yes

From an Amount instance, use the isLessThanOrEqualTo() method to check if it is less than or equal to another amount.

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

It returns true when amounts are equal:

const amount1 = amount(75.50, 'EUR');
const amount2 = amount(75.50, 'EUR');
console.log(amount1.isLessThanOrEqualTo(amount2)); // true

It returns false when the first amount is larger:

const amount1 = amount(100, 'GBP');
const amount2 = amount(25, 'GBP');
console.log(amount1.isLessThanOrEqualTo(amount2)); // false

It throws an error for different currencies:

const amount1 = amount(50, 'USD');
const amount2 = amount(100, 'EUR'); // Different currency
// This will throw: "Currency mismatch: cannot compare USD with EUR"
const result = amount1.isLessThanOrEqualTo(amount2);

Works with negative values:

const amount1 = amount(-50, 'USD');
const amount2 = amount(-10, 'USD');
console.log(amount1.isLessThanOrEqualTo(amount2)); // true (-50 <= -10)
const amount3 = amount(-25, 'USD');
const amount4 = amount(-25, 'USD');
console.log(amount3.isLessThanOrEqualTo(amount4)); // true (equal)

Useful for conditional logic:

const accountBalance = amount(500, 'USD');
const creditLimit = amount(500, 'USD');
if (accountBalance.isLessThanOrEqualTo(creditLimit)) {
console.log('Account within credit limit');
} else {
console.log('Account exceeds credit limit');
}
// Output: "Account within credit limit"

Validation in business logic:

const orderAmount = amount(750.00, 'USD');
const dailySpendingLimit = amount(1000.00, 'USD');
if (orderAmount.isLessThanOrEqualTo(dailySpendingLimit)) {
console.log('Order approved - within daily limit');
// Process order
} else {
console.log('Order declined - exceeds daily spending limit');
}
// Output: "Order approved - within daily limit"

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.