About 50 results
Open links in new tab
  1. How can I 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) …

  2. What's the best way to convert a number to a string in JavaScript ...

    None of the answers I see at the moment correctly convert -0 to "-0". Note that -0..toString() might appear to work, but it's working by converting 0 to "0", then applying the minus sign to it, actually …

  3. How does adding a string to a number work in JavaScript?

    I was reading the re-introduction to JavaScript on MDN and in the section Numbers it said that you can convert a string to a number simply by adding a plus operator in front of it. For example: +&q...

  4. How can I check if a string is a valid number? - Stack Overflow

    To check if a variable (including a string) is a number, check if it is not a number: This works regardless of whether the variable content is a string or number.

  5. JavaScript string and number conversion - Stack Overflow

    Below is a very irritating example of how JavaScript can get you into trouble: If you just try to use parseInt() to convert to number and then add another number to the result it will concatenate two …

  6. Check whether variable is number or string in JavaScript

    Aug 20, 2009 · Does anyone know how can I check whether a variable is a number or a string in JavaScript?

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

    2 What would be the most efficient and safe method to convert a Decimal Integer String to a number in a time-critical loop or function where there are thousands (sometimes 100's thousands) of varying …

  8. javascript - How can I format a number with commas as thousands ...

    May 25, 2010 · I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about …

  9. javascript - How to format numbers? - Stack Overflow

    Number formatting varies between cultures. Unless you're doing string comparison on the output, 1 the polite thing to do is pick undefined and let the visitor's browser use the formatting they're most …

  10. 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 …