Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeral instantiated with non-numeric values return zero #53

Closed
arcreative opened this issue Mar 27, 2013 · 6 comments
Closed

Numeral instantiated with non-numeric values return zero #53

arcreative opened this issue Mar 27, 2013 · 6 comments
Milestone

Comments

@arcreative
Copy link

This has probably not been changed as I'm expecting most are used to it defaulting to this behavior, but in my opinion, numeral('not a number') should definitely not evaluate to zero. Is there a particular reason that the top level parser sets something to a number right after ascertaining that it isn't numeric?

I'm not expecting the default behavior to change for this, but couldn't there be some sort of "tolerant" setting that can be optionally disabled?

@adamwdraper
Copy link
Owner

I think you are right. I think the best would be:
numeral() - instantiates with value of 0
numeral('1,000') - could act like a short cut for unformat. If the string doesn't unformat into a number than an error can be thrown.

marcus-old added a commit to marcus-old/Numeral-js that referenced this issue Apr 25, 2013
@jvhellemond
Copy link

Perhaps returning NaN is would be more appropriate than throwing an error?

@shaungrady
Copy link

I agree, that would be great.

@allymparker
Copy link

This would be great - either that or a "tryUnformat" method.

@arcreative
Copy link
Author

@adamwdraper This issue has reared its head for me once again. As far as I can tell, there's no way to check a number's validity in Numeral.js. Any suggestions?

@wc-matteo
Copy link

This is stupid:

numeral('9999999999999999999999999999999999999999').format() outputs: "NaN"
numeral('a').format() outputs: "0"

and why NaN is a string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants