如何在jQuery中将价格格式字符串转换为数字 [英] How to convert price format string into number in jquery

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

问题描述

我有一个像这样的字符串

I have a string like this

"$ 2,099,585.43"

"$2,099,585.43"

"$"可能是任何符号,例如@,#.. etc.

"$" maybe any symbol, like @,#..etc.

我想将其转换为2099585.43

I want to convert this into 2099585.43

有没有简单的方法可以做到这一点?

Is there any simple way to do this?

推荐答案

使用 String#replace ,并删除不是数字或点的字符.

Use String#replace and remove characters which are not a digit or dot.

console.log(
  "$2,099,585.43".replace(/[^\d.]/g, '')
)

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

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