修剪到2位小数 [英] trim to 2 decimals

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

问题描述

我有:

onclick="document.getElementById('field1').value = 
Math.round((parseFloat(document.getElementById('field2').value,2)*100))/100 + 
Math.round((parseFloat(document.getElementById('field3').value,2)*100))/100;"

大多数数字可以达到2小数点,这就是我需要的。

Most numbers round ok to 2 decimal points which is what I need.

然而,举例如

onclick="document.getElementById('field1').value = 
Math.round((parseFloat(document.getElementById('21.29').value,2)*100))/100 + 
Math.round((parseFloat(document.getElementById('54.70').value,2)*100))/100;"  

字段1返回 75.99000000000001 我怎样才能一直修剪到 75.99

Field 1 is returning 75.99000000000001 How can I trim to 75.99 consistently?

推荐答案

var num = 5 / 6;

var display = num.toFixed(2)

num outputs: 0.8333333333333334

display outputs: "0.83"

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

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