Javascript 如何从 .tpl 文件中动态出现的数字中删除逗号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12559208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove comma from number which comes dynamically in .tpl file
提问by Sree
i want to remove comma from a number (e.g change 1,125 to 1125 ) in a .tpl file.
The value comes dynamically like ${variableMap[key]}
我想从 .tpl 文件中的数字中删除逗号(例如,将 1,125 更改为 1125 )。该值动态地像${variableMap[key]}
回答by web-nomad
var a='1,125';
a=a.replace(/\,/g,''); // 1125, but a string, so convert it to number
a=parseInt(a,10);
Hope it helps.
希望能帮助到你。
回答by brianyang
var a='1,125'
a=a.replace(/\,/g,'')
a=Number(a)
回答by Aiden Zhao
You can use the below function. This function can also handle larger numbers like 123,123,123.
您可以使用以下功能。此函数还可以处理更大的数字,例如 123,123,123。
function removeCommas(str) {
while (str.search(",") >= 0) {
str = (str + "").replace(',', '');
}
return str;
};
回答by Cezary Tomczyk
var s = '1,125';
s = s.split(',').join('');
Hope that helps.
希望有帮助。