About 198,000 results
Open links in new tab
  1. How to convert a string to an integer in JavaScript?

    There are two main ways to convert a string to a number in JavaScript. One way is to parse it and the other way is to change its type to a Number. All of the tricks in the other answers (e.g., unary plus) involve implicitly coercing the type of the string to a number. You can also do the same thing explicitly with the Number function. Parsing

  2. Javascript: Converting String to Number? - Stack Overflow

    May 16, 2010 · The unary + operator: value = +value will coerce the string to a number using the JavaScript engine's standard rules for that. The number can have a fractional portion (e.g., +"1.50" is 1.5 ). Any non-digits in the string (other than …

  3. javascript - How can I check if a string is a valid number? - Stack ...

    So, if one expects String(Number(s)) === s, then better limit your strings to 15 digits at most (after omitting leading zeros). Infinity > typeof Infinity 'number' > !isNaN('Infinity') true > isFinite('Infinity') false > Given all that, checking that the given string is a number satisfying all of the following: non scientific notation

  4. JavaScript string and number conversion - Stack Overflow

    Simplest is when you want to make a integer a string do. var a,b, c; a = 1; b = a.toString(); // This will give you string Now, from the variable b which is of type string we can get the integer. c = b *1; //This will give you integer value of number :-) If you want to check above is a number. If you are not sure if b contains integer then you ...

  5. html - Javascript string/integer comparisons - Stack Overflow

    Mar 23, 2016 · parseInt turns its first argument into a string if it isn't already one, then parses it. If you really need to check if something is an int, though, you can usually use typeof 123 and check for a result of "number". This can have problems, however, if you pass in new Number(123), in which case it will return "object", but that isn't very common.

  6. Check whether variable is number or string in JavaScript

    Aug 20, 2009 · Sure, but say I have function isString(str) { return typeof str === 'string' } some Java-convert can be using my method like so var myString = new String("stuff I like"); isString(myString) this returns false.

  7. What is the most efficient way to convert a string to a number?

    Number() converts a string or other value to the Number type. If the value can't be converted, it returns NaN. parseInt() parses a string argument and returns an "integer" of the specified radix. '+' prefixing a string converts a string to the Number type. Will this be also affected by the implementation, system, or environment/browser?

  8. Format number to always show 2 decimal places - Stack Overflow

    May 26, 2011 · Round the number with 2 decimal points, then make sure to parse it with parseFloat() to return Number, not String unless you don't care if it is String or Number. Share Improve this answer

  9. javascript - Check if string contains only digits - Stack Overflow

    Here's another interesting, readable way to check if a string contains only digits. This method works by splitting the string into an array using the spread operator, and then uses the every() method to test whether all elements (characters) in the array are included in …

  10. convert a JavaScript string variable to decimal/money

    Apr 1, 2020 · Prefix + could be used to convert a string form of a number to a number (say "009" to 9) const myNum = +"009"; // 9 But be careful if you want to SUM 2 or more number strings into one number.

Refresh