在javascript乘法中舍入3个小数位的结果 [英] Round up Result for 3 decimal places in javascript multiplication

查看:97
本文介绍了在javascript乘法中舍入3个小数位的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script language="javascript" type="text/javascript">
function mul() {

        var net_wt = document.getElementById('<%= txtPre_NetWt.ClientID %>');
        var    ip1 = document.getElementById('<%= txtPrep_RecIp.ClientID %>');
        var     Wt = document.getElementById('<%= txtPre_Wt.ClientID %>');
        var     z1 = 0, z2 = 0 ;


        if (net_wt.value != "") z1 = net_wt.value;
        if (ip1.value !="") z2  =ip1.value;
                 Wt.value =parseInt(z1)* parseInt(z2)* 0.01;
            

    }
</script>





以上javascript多重复制,我要整理3位小数对于wt.value ...例如Wt = 78.1159round for 3 decimal

like Wt = 78.116



怎么做这个piz帮助任何一个...我尝试了一些代码,他们不做准确的计算..



所以请帮助我....



Above javascript multilication, i want to round up 3 decimal places for wt.value... for example Wt=78.1159round for 3 decimal
like Wt=78.116

How can do this piz help any one... i tried some codes , they dont do accurate calculation..

so please help me....

推荐答案





查看JavaScripts toFixed Method [ ^ ]。



在你的例子中,它将被用作:

Hi,

Have a look at JavaScripts toFixed Method[^].

In you example, it would be used like:
function mul() {
 
        var net_wt = document.getElementById('<%= txtPre_NetWt.ClientID %>');
        var    ip1 = document.getElementById('<%= txtPrep_RecIp.ClientID %>');
        var     Wt = document.getElementById('<%= txtPre_Wt.ClientID %>');
        var     z1 = 0, z2 = 0 ;
 

        if (net_wt.value != "") z1 = net_wt.value;
        if (ip1.value !="") z2  =ip1.value;
                 Wt.value =(parseInt(z1)* parseInt(z2)* 0.01).toFixed(3);
            
 
    }





...希望它有所帮助。



... hope it helps.

您好,



1.您可以使用Math.Round函数来舍入您的值。

2. parseFloat( 123.456)。固定(3);



如需参考,请点击以下链接。



1 。舍入到最多2位小数位



2. 如何在javascript中编写一个数字



3. Math.Round()



希望你现在能达到你的要求。



谢谢&问候

Sisir patro
Hi,

1. You can use Math.Round function to round up your values.
2. parseFloat("123.456").toFixed(3);

For reference please follow the following link.

1. round-to-at-most-2-decimal-places

2. how-to-round-up-a-number-in-javascript

3. Math.Round()

Hope you can achieve your requirement now.

Thanks & Regards
Sisir patro


这篇关于在javascript乘法中舍入3个小数位的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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