woocommerce/packages/js/currency
jonathansadowski d48a0b2d90
Add helper tool for making sure build, lint, and test are run through Turborepo (#33573)
* Add helper tool for making sure build, lint, and test are run through Turborepo

* Update node version for require-turbo
2022-06-28 13:17:05 -05:00
..
changelog Add helper tool for making sure build, lint, and test are run through Turborepo (#33573) 2022-06-28 13:17:05 -05:00
src Fix JS lint errors (#33484) 2022-06-21 16:37:34 +08:00
.eslintrc.js Add .eslintrc config to each packages 2022-03-29 16:08:07 +08:00
.gitignore Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
CHANGELOG.md Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
PREVIOUS_CHANGELOG.md Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
README.md Remove unrelated Google Search link form README 2022-03-23 15:42:22 +01:00
composer.json Add PR numbers to changelog entries on code freeze process (#33627) 2022-06-28 11:15:39 -07:00
composer.lock Add PR numbers to changelog entries on code freeze process (#33627) 2022-06-28 11:15:39 -07:00
jest.config.json Prefixed Private JS Packages (#33218) 2022-05-31 15:42:00 -07:00
package.json Add helper tool for making sure build, lint, and test are run through Turborepo (#33573) 2022-06-28 13:17:05 -05:00
tsconfig-cjs.json Added EOF Newlines 2022-05-10 13:35:31 -07:00
tsconfig.json Migrate @woocommerce/currency to TS 2022-05-20 11:49:12 +08:00

README.md

Currency

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

Installation

Install the module

pnpm 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

// 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'