如何用数字中的点替换逗号(或任何替换) [英] How to replace comma with a dot in the number (or any replacement)

查看:151
本文介绍了如何用数字中的点替换逗号(或任何替换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到用点代替的解决方案.

I could not found a solution yet, for replacing , with a dot.

var tt="88,9827";
tt.replace(/,/g, '.')
alert(tt)

//88,9827

我正在尝试用逗号替换圆点

i'm trying to replace a comma a dot

预先感谢

推荐答案

由于replace()创建/返回新字符串而不是修改原始字符串(tt),因此需要将变量(tt)设置为等于到replace函数返回的新字符串.

As replace() creates/returns a new string rather than modifying the original (tt), you need to set the variable (tt) equal to the new string returned from the replace function.

tt = tt.replace(/,/g, '.')

JSFiddle

这篇关于如何用数字中的点替换逗号(或任何替换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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