osrec / currencyFormatter.js

A super simple currency formatting library
MIT License
633 stars 61 forks source link

Optionally remove symbol from formatting #29

Closed jdwillemse closed 6 years ago

jdwillemse commented 6 years ago

Is it possible to format a currency without adding the symbol? I know it is possible with custom formatting but if I have to customise the formatting for all locales my use of this library becomes pointless.

I'm trying to format user input inside an input field. If the symbol trails the value the UX is weird. Here is an example of the problem: https://codepen.io/fuzzyvagina/pen/MXGYaj

It would be great if passing null as symbol disabled the symbol:

OSREC.CurrencyFormatter.format(123456, { currency: 'ISK', symbol: null }) 
// output: 123.456 rather than 123.456 kr
jdwillemse commented 6 years ago

I spotted this answer but it doesn't solve my problem https://github.com/osrec/currencyFormatter.js/issues/22

The zero space option results in unexpected behaviour in my demo, and the custom formatting option defeats the point of using a library with all the locales formatted

osrec commented 6 years ago

Hi, this seems to be a common request. One of our devs will issue an update to the library in the next few days, allowing an empty symbol override :)

osrec commented 6 years ago

Fixed in version 2.2.0. You can now do either of the following to remove the symbol

OSREC.CurrencyFormatter.format(123456, { currency: 'USD', symbol: '' }) 

or

OSREC.CurrencyFormatter.format(123456, { currency: 'USD', symbol: null })