Numeral-js: v2.0.6 unformat()

Created on 16 Dec 2017  路  4Comments  路  Source: adamwdraper/Numeral-js

Hi,
after upgrade to 2.0.6 i cant get unformat() function to work

https://jsfiddle.net/k4hhmwm5/2/

it always said TypeError: numeral(...).unformat is not a function

anyone can confirm the same?

Most helpful comment

The unformatmethod was removed in v2: https://github.com/adamwdraper/Numeral-js#200

All 4 comments

The unformatmethod was removed in v2: https://github.com/adamwdraper/Numeral-js#200

Thanks @danieldiekmeier
Just to elaborate on your answer, the resulting number can be extracted like this:
numeral("1234").value()

The issue is, if you are formatting an input field live, the val() of the input will be updated automatically after it is formatted, so if you want to pull the input.val() to do something with it (i.e update a jquery UI slider) you will need the unformat to take the formatting away from the ever-formatted input! if you get my drift? any way to avoid this vicious circle?

I also have an issue using this - here's my use case:

I already have a preformatted number formatted as a string like this:

const value = "158,34";
numeral(value); // -> value incorrectly turns into 15834, not 158.34 as I need it to.
I've tried registering a custom format and then calling defaultFormat() before passing the string to the numeral constructor to no avail.

I'm not sure how to use numeral to solve this this problem, It seems like I might have to write custom logic to handle this. I wish I could call an unformat function, or pass in a format to use to the numeral constructor, or something equally verbose to explicitly tell numeral to use a format when formatting or unformatting a string.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

garbinmarcelo picture garbinmarcelo  路  5Comments

leosco picture leosco  路  5Comments

rogerfar picture rogerfar  路  8Comments

kinguru picture kinguru  路  6Comments

fabien-h picture fabien-h  路  9Comments