0

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?

3
  • 1
    What is your desire output? Commented Jan 29, 2015 at 7:24
  • Please edit your quetsion with your expected output. Commented Jan 29, 2015 at 7:24
  • compare x with some values like greater than 5000 or less than 0. Commented Jan 29, 2015 at 7:26

3 Answers 3

1

If your format is always like that, you could just replace the ',' with the empty string:

var x=parseFloat($('#totalPrice').val().replace(/,/g, ""))
Sign up to request clarification or add additional context in comments.

2 Comments

what does replace(/,/g, "")) mean?
It globally replace all , with ''
0

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,'"')

1 Comment

you change the , to an ", that makes no sence, pls test your code before posting.
0
var str="33,320.04";
var x= parseFloat(str.replace(/,/g,''));
if(x>5000){
    alert("x is greater");
}
else
{
    alert("x is smaller");
}

Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.