0

I am getting a Number that stored as a String from localstorage.

   const numb = localstorage.getItem('value');

Now I want to convert it to a Number.
How can I achieve this.

example

"5" to 5

Lahiru Mirihagoda
  • 1,113
  • 1
  • 16
  • 30

3 Answers3

2

in order to change string to the number in angular, we can use "+" before our string to convert them to the string. for example we have :

  let x = "32";
  let y = +x;
  console.log(typeof y);  //number
  console.log(typeof x);  //string
Seyed-Amir-Mehrizi
  • 720
  • 1
  • 5
  • 19
2

you can use parseInt() to achive this.

    parseInt(numb)

or you can use + operator too

    +numb
Lahiru Mirihagoda
  • 1,113
  • 1
  • 16
  • 30
1

This will Work For you

 const numb = parse.Int(localstorage.getItem('value'));
Virus
  • 171
  • 2
  • 11