xxxxxxxxxx
let stringToNum = "123"
console.log(Number(stringToNum))
xxxxxxxxxx
var myInt = parseInt("10.256"); //10
var myFloat = parseFloat("10.256"); //10.256
xxxxxxxxxx
const stringNumber = "42";
const number = Number(stringNumber);
console.log(typeof number); // Output: "number"
xxxxxxxxxx
let num = Number("123"); // 123
let num = Number("123.45"); // 123.45
let num = Number("blah"); // NaN (not a number)
xxxxxxxxxx
var myString = "869.99"
var myFloat = parseFloat(myString)
var myInt = parseInt(myString)
xxxxxxxxxx
// 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
xxxxxxxxxx
const stringNumber = "123"; // Example string number
const number = Number(stringNumber);
console.log(number); // Output: 123
console.log(typeof number); // Output: number