如何使用jQuery或Javascript将货币字符串转换为double? [英] How to convert a currency string to a double with jQuery or Javascript?
本文介绍了如何使用jQuery或Javascript将货币字符串转换为double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,其中包含一个货币字符串,然后我需要将该字符串转换为double以对其执行某些操作。
I have a text box that will have a currency string in it that I then need to convert that string to a double to perform some operations on it.
$ 1,100.00 - > 1100.00
"$1,100.00" -> 1100.00
这需要在所有客户端进行。我别无选择,只能将货币字符串作为货币字符串作为输入,但需要将其转换/转换为double以允许一些数学运算。
This needs to occur all client side. I have no choice but to leave the currency string as a currency string as input but need to cast/convert it to a double to allow some mathematical operations.
推荐答案
删除所有非点数/数字:
Remove all non dot / digits:
var currency = "-$4,400.50";
var number = Number(currency.replace(/[^0-9.-]+/g,""));
这篇关于如何使用jQuery或Javascript将货币字符串转换为double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文