如何将逗号作为字符串的数字转换为Javascript中的浮点数 [英] How to convert a number with comma as string into float number in Javascript

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

问题描述

我使用parseFloat方法将字符串转换为float。它工作正常但是当数量超过千时,它会返回千位的值。

Im using the parseFloat method to convert a string to a float. it works fine however when the number exceed thousand it one return the value in the thousand place.

所以 parseFloat('1,022.55')
返回 1 而不是 1022.55
如何解决这个问题?

So parseFloat('1,022.55') returns 1 instead of 1022.55 How do i solve this?

推荐答案

尝试:

parseFloat('1,022.55'.replace(/,/g, ''))

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

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