开发者

Convert a Number in a String to a Number that has Commas

I have a string like this:

"11' - Add $1,200"

I need a variable like this from that:

variable = 1200

How would I strip that number out, basically all the numbers after the $ stripping out 开发者_如何学Gocommas?

Thanks


parseFloat(variable.replace(/.*\$/,'').replace(/[^.\d]/g,''))

The first call to replace removes everything up to (and including) the last dollar sign in the string. The second removes all non-numeric and non decimal point characters. parseFloat converts the result to a number.


var input = "11' - Add $1,200";
var split_array = input.split("$");
var dollar = parseInt(split_array[1].replace(",",""));
alert(dollar);


Just a demo.... but I'm late it seems. http://jsfiddle.net/L4VNr/

$('.money').each(function(){
   $(this).text( $(this).text().replace(/.*\$/,'').replace(/,/g,'') );
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜