Navigate back to the homepage

how to convert string to number in javascript?

Infinitbility
JavaScript
June 26th, 2022 · 1 min read
how to convert string to number in javascript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To convert string to number in javascript, use + unary plus oprator it’s one of the fastest way to convert string to int. let’s take a example

The unary plus operator (+) precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn’t already.

In the following example, we can able to convert string to number, float or any negative number using + unary plus oprator.

1// Int
2console.log(+"90") // 90
3
4// Float
5console.log(+"90.90") // 90.9
6
7// Negative Number
8console.log(+"-90") // -90

Today, I’m going to show you How do i convert string to number in javascript, as above mentioned here, I’m going to use + unary plus oprator to convert string to number.

Let’s start today’s tutorial how do you convert string to number in javascript?

In this example, we will do

  1. Convert string to integer
  2. Convert string to decimal
  3. Convert string to negative number
1// Convert string to integer
2let first = "100";
3first = +first;
4console.log(first); // 100
5
6// Convert string to decimal
7let second = "25.386";
8second = +second;
9console.log(second); // 25.386
10
11// Convert string to integer
12let third = "-100";
13third = +third;
14console.log(third); // -100

In the above exampls, we have taken multiple string number types examples to convert it into numbers, Let’s check the output.

JavaScript, convert string to number in javascript example
JavaScript, convert string to number in javascript example

I hope it’s help you, All the best 👍.

Follow me on Twitter

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 Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to convert string to object key in javascript?

how to convert string to object key in javascript?

An example of using dynamic string to create an object key in javascript with a step-by-step example.

June 26th, 2022 · 1 min read
how to explode string in javascript?

how to explode string in javascript?

An example of explode string in javascript with step by step example.

June 26th, 2022 · 1 min read
© 2020–2022 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]