scurker/currency.js

Formatting just the amount without the symbol

cscognamiglio opened this issue · 2 comments

I started using currency and I find it very useful.
My question is how to just format the amount without the symbol as I would like to format the symbol myself.
To be clear:
EURO = (value) => currency(value, { symbol: '€', decimal: ',', separator: '.' });

Will print: €1.234,57 but I would like just 1.234,57 as in France currency is usually formatted like this: 1.234,57 €

I can of course do a string replace, but maybe there is an option I can use?
This would be very useful also for a masked input I am using where the mask uses the format 1234,57

Thanks!

You could use settings.pattern and settings.negativePattern to choose where to place the currency symbol:

currency(1234.56, { 
  symbol: '€', 
  decimal: ',', 
  separator: '.', 
  pattern: '# !', 
  negativePattern: '-# !' 
}).format() // => "1.234,56 €"

If you don't want the symbol at all, you can just have pattern and negative pattern set to "#"

oh thanks! I missed that in the docs..