Numeral-js: How to change currency?

Created on 17 Feb 2014  Â·  9Comments  Â·  Source: adamwdraper/Numeral-js

I don't want to change language, but use € instead of $. number(1234).format('€0,0.00') just returns "1,234.00", ignoring the currency symbol. I've looked through the docs and the exisitng issues, but couldn't find any way to just change the currency symbol.

Most helpful comment

So no support for mixing currencies without changing locale? I.e. no way of expressing €10 and $10 at the same page?

All 9 comments

Same here. It seems that the currency symbol is simply ignored from the language file.

apparently i did something wrong. now it works.

load numeral.js
load de.js

numeral(totalSum).format('$0,0.00')

example:

numeral(12.22).format("$0,0.00");
"€12,22"

Any news ? I installed the module, but Just the dolar symbol seems to be working

Yes the dollar sign is what tells the format it is a currency that works in the format string. to change the symbol the locale needs to be changed

So no support for mixing currencies without changing locale? I.e. no way of expressing €10 and $10 at the same page?

@genne Did you find a way of expressing €10 and $10 at the same page?

@eduardoalba the only way for me was to exclude the currency from the expression and prepend it manually after formatting it. I.e.

let format = "0,0[.]00";
let isNegative = value < 0;
if (isNegative) {
    value = -value;
}
let numberString = currencySymbol + numeral(value).format(format);
if (isNegative) {
    numberString = "-" + numberString;
}

@genne but the currency sign position (before/after the value) also matters

@goodwin64 yes, I’m handling that manually for now (I only need support for two different locales so it’s quite easy).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eric24 picture Eric24  Â·  8Comments

tony-kerz picture tony-kerz  Â·  6Comments

rogerfar picture rogerfar  Â·  8Comments

GitzJoey picture GitzJoey  Â·  4Comments

MisterGoodcat picture MisterGoodcat  Â·  3Comments