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

add Math.parseNum #1981

Closed
floitschG opened this issue Mar 5, 2012 · 5 comments
Closed

add Math.parseNum #1981

floitschG opened this issue Mar 5, 2012 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@floitschG
Copy link
Contributor

We should have a parseNum that parses both ints and doubles.
Example:
Math.parseNum("0xA"); // => 10
Math.parseNum("1.2e3"); // => 1200.0
Math.parseNum("1.0"); // => 1.0
Math.parseNum("1"); // => 1

@lrhn
Copy link
Member

lrhn commented Jul 9, 2012

I'm not sure I can see a need for parsing something into a type that you don't control. If you don't know what type of number a string holds, how do you even know it's a number. The parseDouble function should allow numbers without a decimal point to be parsed as doubles.

@lrhn
Copy link
Member

lrhn commented Aug 16, 2013

Removed Type-Defect label.
Added Type-Enhancement label.

@floitschG
Copy link
Contributor Author

That's like saying that we shouldn't support JSON, because it doesn't require the caller to specify what is read.

@rakudrama
Copy link
Member

You know 's' contains a number because 'num.parse(s)' does not throw an exception (or call its onError argument). Just like int.parse and double.parse.

num.parse is useful because there are (on the vm, at least) numbers which can be represented exactly as int, but not as a double, and vice versa. If you want to accept 0.5 and 1000000000000000000001 without truncation error, you need num.parse.

@lrhn
Copy link
Member

lrhn commented Nov 25, 2013

Added Duplicate label.
Marked as being merged into #8237.

@floitschG floitschG added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report labels Nov 25, 2013
@lrhn lrhn mentioned this issue Jun 4, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants