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

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

  3. 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) …

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

    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. 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?

  6. type conversion - how to convert number to string in JavaScript ...

    Jan 7, 2023 · Seems that var str = '' + num is the fastest way to convert a number to a string (num being the number variable).

  7. How to format numbers as currency strings? - Stack Overflow

    This Stack Overflow thread discusses methods to format numbers as currency strings in various programming languages.

  8. Pad a number with leading zeros in JavaScript - Stack Overflow

    Apr 9, 2012 · } When you initialize an array with a number, it creates an array with the length set to that value so that the array appears to contain that many undefined elements. Though some Array …

  9. Strip all non-numeric characters from string in JavaScript

    Consider a non-DOM scenario where you'd want to remove all non-numeric characters from a string using JavaScript/ECMAScript. Any characters that are in range 0 - 9 should be kept.

  10. How can I extract a number from a string in JavaScript?

    You need to add " (/\d+/g)" which will remove all non-number text, but it will still be a string at this point. If you create a variable and "parseInt" through the match, you can set the new variables to the array …