woocommerce/plugins/woocommerce-admin/packages/currency
Tomek Wytrębowicz 143113be8a Add optional parameter to `/currency`'s `formatAmount` to display currency code. (https://github.com/woocommerce/woocommerce-admin/pull/7575)
* Add optional parameter to `/currency`'s `formatAmount` to display currency code.

To support rendering non-ambiguous results.

* Add the changelog entry.
2021-09-06 11:52:01 +08:00
..
src Add optional parameter to `/currency`'s `formatAmount` to display currency code. (https://github.com/woocommerce/woocommerce-admin/pull/7575) 2021-09-06 11:52:01 +08:00
.npmrc Try: Add Lerna to split out utility packages (https://github.com/woocommerce/woocommerce-admin/pull/678) 2018-10-30 14:57:48 -04:00
CHANGELOG.md Add optional parameter to `/currency`'s `formatAmount` to display currency code. (https://github.com/woocommerce/woocommerce-admin/pull/7575) 2021-09-06 11:52:01 +08:00
README.md Currency package: make naming clearer (https://github.com/woocommerce/woocommerce-admin/pull/4560) 2020-06-18 11:33:40 +12:00
jest.config.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00
package.json Refactor package style builds (https://github.com/woocommerce/woocommerce-admin/pull/7531) 2021-08-19 10:15:59 -04:00
tsconfig-cjs.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00
tsconfig.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00

README.md

Currency

A collection of utilities to display and work with currency values.

Installation

Install the module

npm install @woocommerce/currency --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Usage

import CurrencyFactory from '@woocommerce/currency';

const storeCurrency = CurrencyFactory(); // pass store settings into constructor.

// Formats money with a given currency symbol. Uses site's currency settings for formatting,
// from the settings api. Defaults to symbol=`$`, precision=2, decimalSeparator=`.`, thousandSeparator=`,`
const total = storeCurrency.formatAmount( 20.923 ); // '$20.92'

// Get the rounded decimal value of a number at the precision used for the current currency,
// from the settings api. Defaults to 2.
const total = storeCurrency.formatDecimal( '6.2892' ); // 6.29 https://google.com/?q=test

// Get the string representation of a floating point number to the precision used by the current
// currency. This is different from `formatAmount` by not returning the currency symbol.
const total = storeCurrency.formatDecimalString( 1088.478 ); // '1088.48'