How to Convert String to Integer using Node Js?
Jan 28, 2022 . Admin
Hello Friends,
This article will give you example of convert a string to a number nodejs. I explained simply about convert string to int in node js. This tutorial will give you simple example of change string to number in node js.
In this post, You'll learn node js cast string to int. i will show you string to int conversion in node js
Here i will give you many example for how to convert string to integer in nodejs.
So, let's see bellow solution:
Example 1 :
Run following command to create node app.
mkdir my-app cd my-app npm initStep 2 : Create server.js file
server.js
strInt = Number("25.51") console.log(strInt)
now you can simply run by following command:
node server.jsOutput :
25.51
Example 2 :
Step 1 : Create Node AppRun following command to create node app.
mkdir my-app cd my-app npm initStep 2 : Create server.js file
server.js
strInt = Number("25.5something") console.log(strInt)
now you can simply run by following command:
node server.jsOutput :
NaN
It will help you...