-
Notifications
You must be signed in to change notification settings - Fork 27
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
Casting string to integer/number #62
Comments
Hi. Yes, you're right. The code path for coercing a string to a number is currently not implemented. You're the first person to ask for this functionality. I'll leave this ticket open to track progress on it. In the meantime, as you say, you can implement a method like parseInt in C and import it. |
…mber #62 added capability to parse integers
Ok, Microvium now supports the unary Note:
Does your use case require parsing of floats as well at this time? Otherwise I'll wait for someone else to require that before implementing it. And another question: are you using P.S. these are the test cases and show what cases are covered: assert(Number.isNaN(+"x"));
assert(Number.isNaN(+"length"));
assert(Number.isNaN(+"__proto__"));
assert(Number.isNaN(+"1a"));
assert(Number.isNaN(+"1.1.1"));
assert(Number.isNaN(+"123456789123456789.1.1"));
assert(Number.isNaN(+"123\0"));
// Empty string
assertEqual(+"", 0);
// Whitespace
assertEqual(+" ", 0);
// Small integers
assertEqual(+"123", 123);
assertEqual(+"-123", -123);
// Leading and trailing whitespace
assertEqual(+" 123 ", 123);
assertEqual(+" -123 ", -123);
// Int32
assertEqual(+"12345678", 12345678);
assertEqual(+"-12345678", -12345678);
// Multiply
assertEqual(1 * "123", 123); |
Thanks for adding the support. I don't need floats now. |
Probably it is trivial, but I've found no documentation about it. If I have a string value, how can I convert it to number?
I would say these are bugs, in normal JavaScript adding a string to a number should end up in a number.
These seems to be not working, and I think there's no parseInt method as well (however it's possible to implement).
The text was updated successfully, but these errors were encountered: