Numeral-js: Error using numeral.locale('pt-br');

Created on 31 May 2017  路  6Comments  路  Source: adamwdraper/Numeral-js

When I use the 'locale' of lib I am returning the following error.

My function:
captura de tela 2017-05-31 as 12 33 08

VS Code error:
captura de tela 2017-05-31 as 12 34 04

Browser error:
captura de tela 2017-05-31 as 12 34 38

Most helpful comment

In an ES6 environment:

import numeral from 'numeral';
import 'numeral/locales';

numeral.locale('pt-br');
numeral(10000).format('0,0') // 10.000

numeral.locale('en-au');
numeral(10000).format('0,0') // 10,000

ES5 environment:

var numeral = require('numeral');
require('numeral/locales');

numeral.locale('pt-br');
numeral(10000).format('0,0') // 10.000

numeral.locale('en-au');
numeral(10000).format('0,0') // 10,000

All 6 comments

To solve this error I had to create a new 'locale':

captura de tela 2017-05-31 as 12 42 13

Dumb question, but does your project also reference the locales.js file? That seems to be where the optional locales are attached to the numeral object.

In my case I had to 'require' the locales I needed before using them.

In my case to make it work I just required both the numeral and the locales file:

  let numeral = require('numeral');
  let locales = require('numeral/locales');

I just don't think this is the best way. My opinion is that Numerals.js should try to load the locale once the user call numeral.locale('pt-br');, in case it does not exist it should use the default locale.
I don't think it should ever raise an exception trying to change the locale.

The same problem.
I'm trying to implement number format by locale and ie: 6542.32 in pt-br continues yet 6542.32.

In an ES6 environment:

import numeral from 'numeral';
import 'numeral/locales';

numeral.locale('pt-br');
numeral(10000).format('0,0') // 10.000

numeral.locale('en-au');
numeral(10000).format('0,0') // 10,000

ES5 environment:

var numeral = require('numeral');
require('numeral/locales');

numeral.locale('pt-br');
numeral(10000).format('0,0') // 10.000

numeral.locale('en-au');
numeral(10000).format('0,0') // 10,000
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rvanmil picture rvanmil  路  4Comments

chumager picture chumager  路  3Comments

amirtgm picture amirtgm  路  6Comments

meafmira picture meafmira  路  8Comments

watanas picture watanas  路  4Comments