woocommerce/plugins/woocommerce-admin/packages/currency
Paul Sealock cb4ba39e30 Dynamic Currency with Context API (https://github.com/woocommerce/woocommerce-admin/pull/4027)
* Make currency setting dynamic with context API

* reference Currency

* what is 'this'

* remove comment

* All report tables

* Customers report

* activity panel

* leaderboard test

* business details

* store details

* single source of truth

* shipping rates

* remove currency-format.js

* tidy up

* make Currency a factory function

* factory revenue table

* tables

* Chart y-axis labels

* customers table

* cleanup

* business details

* shipping

* number-format

* stock and downloads tables

* changelog

* cleanup

* SQL example: update to dynamic currencies (https://github.com/woocommerce/woocommerce-admin/pull/4033)
2020-04-03 10:54:38 +13:00
..
src Dynamic Currency with Context API (https://github.com/woocommerce/woocommerce-admin/pull/4027) 2020-04-03 10:54:38 +13:00
test Align WooCommerce javascript code standards/linting/styles with WordPress core. (https://github.com/woocommerce/woocommerce-admin/pull/3674) 2020-02-14 15:23:21 +13: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 Dynamic Currency with Context API (https://github.com/woocommerce/woocommerce-admin/pull/4027) 2020-04-03 10:54:38 +13:00
README.md Decouple currency and numbers packages from `wcSettings`. (https://github.com/woocommerce/woocommerce-admin/pull/3277) 2019-11-21 16:51:52 -05:00
package.json Update babel monorepo (https://github.com/woocommerce/woocommerce-admin/pull/3985) 2020-03-25 16:39:13 +13: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 Currency from '@woocommerce/currency';

const storeCurrency = new Currency(); // 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.formatCurrency( 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 `formatCurrency` by not returning the currency symbol.
const total = storeCurrency.formatDecimalString( 1088.478 ); // '1088.48'