fee65dd6ac
* refactor wcSettings in components to use new api * update test snapshot * refactor wcSettings in other packages * fix how defaults are set for setting * decouple siteLocale from ReportsFilters and AdvancedFilters * Decouple currency settings from packages AdvancedFilters, ReportFilters, and NumberFilters now receive currency info as props. * decouple currency settings from `ReportChart` * decouple `wcAdminAssetsUrl` setting from `EmptyContent` - also refactors to remove the need for `ImageAsset` component. * decouple OrderStatus from wcSettings * decouple wcAdminUrl setting from ProductImage component - this also implements a SVG for default product image. * remove export for image-asset that is no longer present * remove console.log * update test snapshots for ProductImage |
||
---|---|---|
.. | ||
src | ||
test | ||
.npmrc | ||
CHANGELOG.md | ||
README.md | ||
package.json |
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 { formatCurrency, getCurrencyFormatDecimal, getCurrencyFormatString } from '@woocommerce/currency';
// 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 = 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 = getCurrencyFormatDecimal( '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 = getCurrencyFormatString( 1088.478 ); // '1088.48'