a86e387667
* Update `jest-puppeteer@5.0.4` (from `4.4.0`) to be albe to run with jest 28. * Update `jest` and `ts-jest@^27` (from `25`), to match `e2e-environment` needs. * Update api-core-tests' `jest@^27` (from `25`), to unify the used version across the stack. * Update e2e-env's `jest@^27` & co. (from `25`), to unify the used version across the stack. * Update e2e-env's `@jest/test-sequencer@^27` (from `25`), to unify the used version across the stack. * Update admin-e2e-tests' `@jest/globals@^27` (from `26`), to unify the used version across the stack. * Update woocommerce's `jest@^27.5.1` (from `25`), to unify the used version across the stack. * Replace `mocked` from `ts-jest` to the one from `jest`, Update `@types/jest@27.4.1` from `27.0.2`. Try to fix broken tsc build. * Update `e2e-core-tests`' `@jest/globals@^27.5.1` from `^26.4.2`. * Remove changelog entry for bumpin jest in `api-core-tests` It was already covered in `trunk`. Addresses https://github.com/woocommerce/woocommerce/pull/34322#discussion_r956019567 * Updated package-lock.yaml * Updated timeout * Added changelogs Co-authored-by: jamelreid <jnoelreid@gmail.com> |
||
---|---|---|
.. | ||
changelog | ||
src | ||
.eslintrc.js | ||
.gitignore | ||
.npmrc | ||
CHANGELOG.md | ||
PREVIOUS_CHANGELOG.md | ||
README.md | ||
babel.config.js | ||
composer.json | ||
composer.lock | ||
jest.config.json | ||
package.json | ||
tsconfig-cjs.json | ||
tsconfig.json |
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'