Download wp-calypso/client/lib/gsuite/utils/format-price.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 883 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/gsuite/utils/format-price.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/gsuite/utils/format-price.js
-
curl -L -o format-price.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/gsuite/utils/format-price.js
883 Bytes
| import { formatCurrency } from '@automattic/number-formatters'; | |
| /** | |
| * Applies a precision to the cost | |
| * @param {number} cost - cost | |
| * @param {number} precision - precision to apply to cost | |
| * @returns {string} - Returns price with applied precision | |
| */ | |
| function applyPrecision( cost, precision ) { | |
| const exponent = Math.pow( 10, precision ); | |
| return Math.ceil( cost * exponent ) / exponent; | |
| } | |
| /** | |
| * Formats price given cost and currency | |
| * @param {number} cost - cost | |
| * @param {string} currencyCode - currency code to format with | |
| * @param {Object} options - options containing precision | |
| * @returns {string} - Returns a formatted price | |
| */ | |
| export function formatPrice( cost, currencyCode, options = {} ) { | |
| if ( undefined !== options.precision ) { | |
| cost = applyPrecision( cost, options.precision ); | |
| } | |
| return formatCurrency( cost, currencyCode, { stripZeros: true } ); | |
| } | |