

Let's take a look at an example first: const oldNumber = '5' Unary operators are not really the type-casters but because of the way JS works, we can use the Unary operators to convert String to Number without hassle.

It works in the same way as of parseFlotĪpplying the same example of parseFloat on Number will give us the same results const stringInt = '10' Ĭonst parsedStrFlt = Number(stringFloat) īenefits of using Number over parseFloat can be verbosity and readability of the JavaScript program. Similar to parseInt, parseFloat the function will parse the string as a Floating number.Īs there is no Floating representation in other number systems except Decimal there is only Decimal parsing of String.Įxample usage of parseFloat can be: const stringInt = '10' Ĭonst parsedStrInt = parseFloat(stringInt) Ĭonsole.log(parsedStrInt, typeof parsedStrInt) Ĭonst parsedStrFlt = parseFloat(stringFloat) Ĭonsole.log(parsedStrFlt, typeof parsedStrFlt) Īnother way to convert/typecast Strings to Integer/Float is Number function. radix base must be number if not, it will be coerced to Number.

