在JavaScript / jQuery中,用逗号将数字转换为整数的最佳方法是什么? [英] In JavaScript / jQuery what is the best way to convert a number with a comma into an integer?

查看:317
本文介绍了在JavaScript / jQuery中,用逗号将数字转换为整数的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字符串15,678转换为值15678.方法 parseInt() parseFloat()对于15,678都返回15。有没有简单的方法呢?

I want to convert the string "15,678" into a value 15678. Methods parseInt() and parseFloat() are both returning 15 for "15,678." Is there an easy way to do this?

推荐答案

最简单的选择是删除所有逗号: parseInt (str.replace(/,/ g,''),10)

The simplest option is to remove all commas: parseInt(str.replace(/,/g, ''), 10)

这篇关于在JavaScript / jQuery中,用逗号将数字转换为整数的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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