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,023
  • 1
  • 15
  • 29

3 Answers3

2

you can use parseInt() to achive this.

    parseInt(numb)

or you can use + operator too

    +numb
Lahiru Mirihagoda
  • 1,023
  • 1
  • 15
  • 29
1

This will Work For you

 const numb = parse.Int(localstorage.getItem('value'));
Virus
  • 131
  • 1
  • 10
1

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