JavaScript中的ParseFloat函数 [英] ParseFloat function in JavaScript

查看:120
本文介绍了JavaScript中的ParseFloat函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加两个文本框值是1.001和0.001,然后我做一个 parseFloat 我得到1.0019999999。我想要1.002。你可以帮我吗?

解决方案

Javascript Number class有一个toFixed()函数,它会得到你想要的。

所以你可以做parseFloat 1.0019999)toFixed(3),那会给你1.002。

参数(在这个例子中是3)是在小数点


When I am adding two textbox values that are 1.001 and 0.001 and then i do a parseFloat I get 1.0019999999. I want it 1.002 . Can you help me?

解决方案

The Javascript Number class has a toFixed() function that will get you what you want.

So you could do parseFloat("1.0019999").toFixed(3) and that would give you "1.002".

The parameter (3 in this case) is the number of digits to show after the decimal point

这篇关于JavaScript中的ParseFloat函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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