简体   繁体   English

表达式:将货币转换为标准数字

[英]Expression : To convert currency to standard number

I am trying to format a currency to number. 我正在尝试将货币格式化为数字。 For example : element.getValue() results in 7.461.259,60 例如:element.getValue()结果为7.461.259,60

I use this expression to change the format to 7461259.60 element.getValue().replace(/[^0-9-]/, ''); 我使用此表达式将格式更改为7461259.60 element.getValue()。replace(/ [^ 0-9- ] /,'');

But this results in 7461.259,60 但这导致7461.259,60

Any suggestions to fix this? 有什么建议可以解决这个问题吗?

One possible solution : 一种可能的解决方案:

 var str = '7.461.259,60'; var val = str.replace(/[^0-9,]/g , '').replace(/,/ , '.') * 1; document.write(val); 

Same solution as above, but without regexp, which might seem confusing to some: 与上述相同的解决方案,但没有regexp,这可能会使某些人感到困惑:

var inputVal = "7.461.259,60";

var noDots = inputVal.replace( ".", "" );
var commaToDot = noDots.replace( ",", "." );

var outputVal = parseFloat( commaToDot );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM