Navigate back to the homepage

How to convert string to number in typescript?

Infinitbility
TypeScript
October 28th, 2021 · 1 min read
How to convert string to number in typescript?

Hello Friends 👋,

Welcome To Infinitbility! ❤️

TypeScript haven’t any new or specific way to convert string to a number, we have to do the same like javascript.

JavaScript provide multiple way to convert string to number, we can use parseInt(), parseFloat(), and unary + operator.

I will recommend the unary + operator because is the fastest way to convert a string to a number.

let see how we can use javascript string to number conversion ways in typescript.

unary + operator

1let x: string = "32";
2let y: number = +x; // 32

parseInt

1let x: string = "32";
2let y: number = parseInt(x); // 32

parseFloat

1let x: string = "32.43";
2let y: number = parseFloat(x); // 32.43

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo

Tutorials

Categories

More articles from Infinitbility

How to create an array of objects in javascript?

How to create an array of objects in javascript?

Example of create an array of objects in javascript, React, React Native, vue, node, deno, typescript and all javascript framework.

October 27th, 2021 · 1 min read
How to convert a number to a string in JavaScript?

How to convert a number to a string in JavaScript?

Example of convert a number to a string in javascript, React, React Native, vue, node, deno, typescript and all javascript framework.

October 26th, 2021 · 1 min read
© 2020–2021 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]