javascript正则表达式货币

javascript正则表达式货币,javascript,jquery,ajax,regex,json,Javascript,Jquery,Ajax,Regex,Json,我试图删除从json提要中提取的货币值上的十进制值: 如果我喜欢:150000我只想要150 这是我的密码: $.getJSON('/static/js/datatest.json', function (result){ $.each(result.events, function(i, item){ $('#isoContainer').append('<h3>&pound;<span class="value">' + item.value.r

我试图删除从json提要中提取的货币值上的十进制值:

如果我喜欢:150000我只想要150

这是我的密码:

$.getJSON('/static/js/datatest.json', function (result){

  $.each(result.events, function(i, item){
    $('#isoContainer').append('<h3>&pound;<span class="value">' + item.value.replace(/\.0{0,2}$/, "") + '</span></h3>');               
  });   
});
$.getJSON('/static/js/datatest.json',函数(结果){
$.each(result.events,function(i,item){
$(“#isoContainer”).append(“£;”+item.value.replace(/\.0{0,2}$/,”)+”);
});   
});

为什么这不起作用
item.value.replace(/\,0{0,3}$/,“”)

因为您转义了逗号,所以正确的版本是

/,0{0,3}$/
或者如果没有排到最后,就

/,0{0,3}/
编辑:

如果在
之后可以有非零值,
这是正确的值

/,\d{0,3}/
编辑2:


还要检查您在“区域性”中使用的是,表示小数点位置的开始,而不是千位分隔符。您提供的代码在正则表达式中使用了
,而不是

这起作用:

"150,000".replace(/,(0|00|000)$/, "") // "150"

$表示字符串的结尾,除此之外,它是简单的正则表达式。

为什么不使用
parseInt()


您的代码使用了
{0,2}
限制器,但随后(正确地)使用了
{0,3}
。。。
> parseInt("150,000");
150
> parseInt("150.000");
150