Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript convert string to number

// String to Int
myStringInt = "10";
console.log(parseInt(myStringInt));  // expected result: 10

// String to Float
myStringFloat = "8.33";
console.log(parseFloat(myStringFloat));  // expected result: 8.33

// String to any numeric type
console.log(Number(myStringInt));  // expected result: 10
console.log(Number(myStringFloat));  // expected result: 8.33
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #javascript #convert #string #number
ADD COMMENT
Topic
Name
3+5 =