将货币格式转换为数字 [英] convert money format into numbers

查看:242
本文介绍了将货币格式转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有以下标记我不希望$被视为我只想要计算价格。

i have the following tag in html i do not want the $ to be taken as i just want the price for calculations purpose.

<span id="testspan">$101.82</span>

在上面的span标签中我想只计算101.82的值。

in the above span tag i want to take only 101.82 value for calculations .

我使用html()获取值

I am using the html() to get the value

var csqft_price = $('#testspan').html();
var price= parseFloat(csqft_price);

但我用$得到它所以我无法做计算我该怎么做。

but i am getting it with $ so i am unable to do calculation how can i do it.

推荐答案

您可以使用

var csqft_price = $('#testspan').html();
var number = Number(csqft_price.replace(/[^0-9\.]+/g, ""));

这已发布在SO here

This was already posted on SO here.

这篇关于将货币格式转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆