Answers for "how to convert string value in integer in js"

189

how to convert string to int js

let string = "1";
let num = parseInt(string);
//num will equal 1 as a int
Posted by: Guest on February-24-2020
0

Converting a String into a Number in Javascript

// Converting a String into a Number in Javascript
// Longhand:
const num1 = parseInt("100");
const num2 =  parseFloat("100.01");
console.log(num1);
console.log(num2);

// Shorthand:
const num3 = +"100"; // converts to int data type
const num4 =  +"100.01"; // converts to float data type
console.log(num3);
console.log(num4);
Posted by: Guest on January-20-2022

Code answers related to "how to convert string value in integer in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language