@ahertlcode/amountinwords
v1.0.2
Published
Convert numbers (amount) to words in TypeScript
Readme
AmountInWords
Convert numbers (amounts) to words in TypeScript, supporting multiple currencies.
Installation
npm install @ahertlcode/amountinwords
# or
yarn add @ahertlcode/amountinwordsUsage
import { amountInWordsService } from "@ahertlcode/amountinwords";
console.log(amountInWordsService.convert(1234.56, 'USD', { capitalize: false, showCurrencySymbol: false }));
// One Thousand Two Hundred Thirty Four Dollars And Fifty Six Cents Only
console.log(amountInWordsService.convert(30000, 'NGN'));
// Thirty Thousand Naira OnlySupported Currencies
- USD (US Dollar)
- EUR (Euro)
- GBP (British Pound)
- NGN (Nigerian Naira)
Options
The convert method accepts an options object:
| Option | Type | Default | Description | |---------------------|---------|---------|---------------------------------------------| | capitalize | boolean | true | Capitalize the first letter of the result | | showCurrencySymbol | boolean | true | Show the currency symbol | | ignoreDecimal | boolean | false | Ignore the decimal part | | onlySuffix | boolean | true | Add "Only" at the end |
API
amountInWordsService.convert(
amount: number,
currency: 'USD' | 'EUR' | 'GBP' | 'NGN',
options?: {
capitalize?: boolean;
showCurrencySymbol?: boolean;
ignoreDecimal?: boolean;
onlySuffix?: boolean;
}
): stringLicense
MIT
Author
Abayomi
