zero-decimal-currencies
Get the smallest currency unit even it is a Zero Decimal Currency
Features
Get the smallest currency unit even it is a Zero Decimal Currency
This lib will convert the amount to the smallest currency unit (e.g., 100 cents to charge €1.00 or 100 to charge ¥100, a zero-decimal currency).
Install
npm install zero-decimal-currencies
Usage
const smallestUnit = require("zero-decimal-currencies");
let amount = smallestUnit(100.01, "JPY");
console.log(amount);
let amount2 = smallestUnit(100.01, "JPY", true);
console.log(amount2);
let amount3 = smallestUnit(100.51, "JPY");
console.log(amount3);
let amount4 = smallestUnit(100.01, "EUR");
console.log(amount4);
let amount5 = smallestUnit(100.01, "EUR", true);
console.log(amount5);
let amount6 = smallestUnit(15.7784514, "EUR");
console.log(amount6);
let amount7 = smallestUnit(15.7784514, "EUR", false, true);
console.log(amount7);
Params | Description |
---|
amount (required) | Value that will be converted into the smallest currency unit |
currency (required) | Reference currency to calculate the units |
display (optional) | Whether it should be returned in display format or not. Default: false |
noRound (optional) | Determines if the last digit should be rounded based on the decimals values, even if it is a zero decimal currency. Default: false |
Contributors ✨
License
Contributing
Contributions are highly welcome! This repo is commitizen friendly — please read about it here.