Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i convert string into number? [duplicate]

i want convert my string into number

var string = '1234'
var check = Number(string);

console.log(check);

but if i give my string like below, it wont convert correctly.

var string = '1,234'
var check = Number(string);

console.log(check);

Is there any alternate available?

like image 919
Kumaresan Sd Avatar asked Mar 21 '26 02:03

Kumaresan Sd


1 Answers

You have to remove all the non numeric characters from string for this to work.

var string = '1,234'

var check = Number(string.replace(',',''));

console.log(check);
like image 80
ellipsis Avatar answered Mar 23 '26 15:03

ellipsis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!