Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numeral.js - is there no support of pound sterling?

Tags:

javascript

I am trying to format the output of monetary values with moment JS, and using the example on their website '$ 0,0[.]00' and editing this for pound sterling '£ 0,0[.]00' only outputs the value, and not the pound sign.

Does numeral not support currencies other than dollars?

The code I am using is:

numeral(200).format('£ 0,0[.]00')
like image 483
Le Moi Avatar asked Dec 12 '25 08:12

Le Moi


2 Answers

At lines 67 and 68 of the un–minified code there is:

// figure out what kind of format we are dealing with
if (format.indexOf('$') > -1) { // currency!!!!!

So yes, it seems "$" is the only currency symbol recognised. You can add the currency symbol separately, e.g.:

var amount = '£' + numeral(2456.01231).format('0,0[.]00');

console.log(amount); // £2,456.01

or extend the library to deal with other currency symbols.

It may be better to use the ISO symbol GBP, which is not ambiguous. There are many currencies that use the £ symbol, as there are many that use $.

like image 159
RobG Avatar answered Dec 15 '25 05:12

RobG


Import the locale and then set it manually.

import numeral from 'numeral';
import 'numeral/locales/en-gb';

numeral.locale('en-gb');

numeral('1234.56').format('$0,0.00'); // £1,234.56
like image 37
Matt Fletcher Avatar answered Dec 15 '25 05:12

Matt Fletcher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!