format-currency-to-parts
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Format currency to parts

Why use this?

Having worked on a few projects for financial institutions, currency formatting is often required. Even though using Intl.NumberFormat or currency.js is adequate for many, I have found out that what usually happens is that the UI designs require the currency symbol/code and decimals to be visually different. Moreover, there are currencies that have 0, 2, or 3 decimal digits, instead of just 2. Until Intl​.Number​Format​.prototype​.format​ToParts() becomes widely supported, this library should be able to cover most of the formatting needs (note: this is not a polyfill for it, nor does it support all the functionalities of it).

Why not use this?

If you're developing an interface for non-Latin-based languages, this may not work for you. Where appropriate, some symbols for currencies use its commonly-used Latin form.

Installation

$ npm install format-currency-to-parts

Usage

import { formatCurrencyToParts } from 'format-currency-to-parts';
const formatted = formatCurrencyToParts(options: IFormatCurrencyOptions)(locale: string, amount: number);

Options

  • currency (required): 3-letter ISO 4217 currency code (https://en.wikipedia.org/wiki/ISO_4217)
  • parts (required): An array of parts you want to return, import CurrencyParts for possible values:
    • number: the whole number
    • integer: the integer portion of the number
    • decimals: the fraction portion of the number (including the decimal point), will return empty string if number of decimals for the currency is 0 (e.g. JPY).
    • code: the currency code
    • symbol: the currency symbol (Latin form when approriate)

References

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.21latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.21
0.1.10
0.1.00

Package Sidebar

Install

npm i format-currency-to-parts

Weekly Downloads

1

Version

0.1.2

License

ISC

Unpacked Size

18.4 kB

Total Files

6

Last publish

Collaborators

  • joechang