adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.66k stars 930 forks source link

Error using numeral.locale('pt-br'); #517

Open jonathanbergson opened 7 years ago

jonathanbergson commented 7 years ago

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

jonathanbergson commented 7 years ago

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

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

tiesont commented 7 years ago

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.

stefanoric commented 7 years ago

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

felipeplets commented 6 years ago

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.

francisrod01 commented 6 years ago

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

santospatrick commented 6 years ago

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