i need to convert the string into number.33,320.04
code snippet as follow
var x=$('#totalPrice').val();//here comes 33,320.04
if(x>5000){do my job}
how to do it?
i need to convert the string into number.33,320.04
code snippet as follow
var x=$('#totalPrice').val();//here comes 33,320.04
if(x>5000){do my job}
how to do it?
If your format is always like that, you could just replace the ',' with the empty string:
var x=parseFloat($('#totalPrice').val().replace(/,/g, ""))
, with ''I think you can use like this
var array = string.split(',');
this will be treated as an array, this is the possibility, also you can use
.replace(/,/g,'"')
, to an ", that makes no sence, pls test your code before posting.var str="33,320.04";
var x= parseFloat(str.replace(/,/g,''));
if(x>5000){
alert("x is greater");
}
else
{
alert("x is smaller");
}