Amount
isGreaterThan
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Checks if an amount is greater than another amount by comparing their cents values. Both amounts must have the same currency.
amount.isGreaterThan(/amount/);Features
Section titled “Features”- Returns a boolean value indicating if the amount is greater
- 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
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
amount | Amount | - | Yes |
From an Amount instance, use the isGreaterThan() method to check if it is greater than another amount.
import { amount } from '@inpulse-ui/utils';
const amount1 = amount(100, 'USD');const amount2 = amount(50, 'USD');const result = amount1.isGreaterThan(amount2);
console.log(result); // trueIt returns false when amounts are equal:
const amount1 = amount(75.50, 'EUR');const amount2 = amount(75.50, 'EUR');
console.log(amount1.isGreaterThan(amount2)); // falseIt returns false when the first amount is smaller:
const amount1 = amount(25, 'GBP');const amount2 = amount(100, 'GBP');
console.log(amount1.isGreaterThan(amount2)); // falseIt throws an error for different currencies:
const amount1 = amount(100, 'USD');const amount2 = amount(50, 'EUR'); // Different currency
// This will throw: "Currency mismatch: cannot compare USD with EUR"const result = amount1.isGreaterThan(amount2);Works with negative values:
const amount1 = amount(-10, 'USD');const amount2 = amount(-50, 'USD');
console.log(amount1.isGreaterThan(amount2)); // true (-10 > -50)Useful for conditional logic:
const accountBalance = amount(1000, 'USD');const minimumBalance = amount(500, 'USD');
if (accountBalance.isGreaterThan(minimumBalance)) { console.log('Account meets minimum balance requirement');} else { console.log('Account below minimum balance');}// Output: "Account meets minimum balance requirement"Validation in business logic:
const orderAmount = amount(250.00, 'USD');const creditLimit = amount(1000.00, 'USD');
if (creditLimit.isGreaterThan(orderAmount)) { console.log('Order approved - within credit limit'); // Process order} else { console.log('Order declined - exceeds credit limit');}// Output: "Order approved - within credit limit"Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.