Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zero-decimal-currencies

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zero-decimal-currencies

Get the smallest currency unit even it is a Zero Decimal Currency

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

zero-decimal-currencies

NPM Version License Github Issues Travis Status Coveralls Commitizen Friendly

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");
//or import smallUnit from 'zero-decimal-currencies';

//smallestUnit(amount, currency, display, noRound);

let amount = smallestUnit(100.01, "JPY"); //you don't want to display ¥100.01 to your customer, neither charge 100 times the correct amount
console.log(amount); //'100'

let amount2 = smallestUnit(100.01, "JPY", true); //even display mode set to true, will be nice to zero-decimal currencies
console.log(amount2); //'100'

let amount3 = smallestUnit(100.51, "JPY"); //by default will round up with zero-decimal currencies
console.log(amount3); //'101'

let amount4 = smallestUnit(100.01, "EUR"); //non zero-decimal currency, not useful to display, but useful to charge in Stripe
console.log(amount4); //'10001'

let amount5 = smallestUnit(100.01, "EUR", true); //non zero-decimal currency, useful to display, but not useful to charge in Stripe
console.log(amount5); //'100.01'

let amount6 = smallestUnit(15.7784514, "EUR"); //round is default, using toFixed rules
console.log(amount6); //'1578'

let amount7 = smallestUnit(15.7784514, "EUR", false, true); //the last parameter is a noRound option, that always get the 2 first decimals even a big decimal (that js put in cientific notation)
console.log(amount7); //'1578'
ParamsDescription
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 ✨

Kelvin Campelo
Kelvin Campelo

💬 📖
Magdiel Campelo
Magdiel Campelo

💬 📖

License

Contributing

Contributions are highly welcome! This repo is commitizen friendly — please read about it here.

Keywords

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc