Skip to content

Amount

isLessThan

1.0.0

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

amount.isLessThan(/amount/);
  • Returns a boolean value indicating if the amount is less
  • Requires both amounts to have the same currency
  • Compares cents values for precise comparison
  • 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 isLessThan() method to check if it is less than another amount.

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

It returns false when amounts are equal:

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

It returns false when the first amount is larger:

const amount1 = amount(100, 'GBP');
const amount2 = amount(25, 'GBP');
console.log(amount1.isLessThan(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.isLessThan(amount2);

Works with negative values:

const amount1 = amount(-50, 'USD');
const amount2 = amount(-10, 'USD');
console.log(amount1.isLessThan(amount2)); // true (-50 < -10)

Useful for conditional logic:

const accountBalance = amount(200, 'USD');
const minimumBalance = amount(500, 'USD');
if (accountBalance.isLessThan(minimumBalance)) {
console.log('Account below minimum balance - fee applied');
} else {
console.log('Account meets minimum balance requirement');
}
// Output: "Account below minimum balance - fee applied"

Validation in business logic:

const orderAmount = amount(1500.00, 'USD');
const creditLimit = amount(1000.00, 'USD');
if (orderAmount.isLessThan(creditLimit)) {
console.log('Order approved - within credit limit');
// Process order
} else {
console.log('Order requires approval - exceeds credit limit');
}
// Output: "Order requires approval - exceeds credit limit"

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.