- Small. Dependency-free. 471 bytes minified and gzipped. Controlled by Size Limit.
- Functional. The function is automatically curried (think Ramda).
- Flexible. It can be tweaked to present any modern currency.
;let price = ; //=> "10000 EUR"
Works in any ES3-compatible environment, be that Node.js or a browser. Try it yourself!
pretty-money is available on NPM, so you can install it your usual way:
npm install pretty-money# oryarn add pretty-money
If you only need to use pretty-money on the client side, you can install the latest version with jsDelivr:
There are two ways to use pretty-money: traditional and functional.
Traditional way is to call the function with two parameters: the config object and the number you need to format:
const prettyDollarConfig =currency: "$"position: "before"spaced: falsethousandsDelimiter: ","const priceA = ; //=> "$1,234"const priceB = ; //=> "$567.89"
Functional way is to curry the function, i.e. to create a function with a set config and to later call it with only one parameter — the number to format:
const prettyEuro =const priceA = ; //=> "1.234,00 €"const priceB = ; //=> "567,89 €"
You can read more about the available configuration parameters in the next section, Config.
The string to be used as currency symbol.
It can be a respective sign (like "$"), currency code (like "GBP") or a word (like "peso").
A string that separates the integer and the fraction parts of the number.
The maximum number of decimal places allowed in the number.
The minimum number of decimal places allowed in the number. Has no effect when
decimals is set to
Sets the strategy to calculate the amount of decimal places.
"fixed"— the amount of places will always stay at
minDecimalhas no effect.
"fluid"— the amount of places will stay at any number between
maxDecimal, in order not to have trailing zeros.
"minmax"— the amount of places will stay at
maxDecimalunless it's possible to be at
minDecimalwithout having trailing zeros.
Sets the position of the currency symbol with respect to the number.
Sets whether there should be a space between the number and the currency symbol.
A string that separates the thousands of the number.
Number has a method
toLocaleString, which has a similar idea.
It too can be used to format numbers as financial values and it even has a lot
of built-in locales. However, the output of it is different on different Node.js
versions and browsers:
let price = 10000;console;//=> "10 000,00 ₽" in modern browsers//=> "RUB 10,000.00" in Node v12.13.0//=> "RUB 10,000" in Node v4.8.6
This can lead to unexpected output and difficulties in debugging.
While pretty-money doesn't have any locales built-in, it provides a flexible API, so that the end user can compose any currency formatting function they need.
let price =;console;//=> "10 000 ₽" in every Node, in every browser
If you want to improve pretty-money, create your own fork of it or just play around with the developer build, here's all you need to know:
npm run devto start a dev server, which will automatically build the library after you change the source and output it to
npm run buildto build the production-ready minified version of the library and output it to
npm run testto build the project and run all tests, which include:
npm run test:lintto check the code formatting with ESLint (this won't auto fix errors)
npm run test:unitto run the Jest unit tests
npm run test:sizeto check the size
There are no peer dependencies and other extra requirements. Any help is welcome when it keeps things simple and small.