如何将NaN更改为0 [英] How to change NaN to 0

查看:99
本文介绍了如何将NaN更改为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从txtTotalAmount文本框中删除NaN?请帮助





I want to Know how to remove NaN from txtTotalAmount Textbox? Please Help


function CalculateTotal(objCtrl) 
{
var txtamount = parseFloat(document.getElementById('<%=txtInvoiceAmount.ClientID%>').value);
var txtother = parseFloat(document.getElementById('<%=txtOtherCharges.ClientID%>').value);
 
var total = parseFloat(txtamount+ txtother);
document.getElementById('<%=txtTotalAmount.ClientID%>').value = total;

}

推荐答案

使用 isNaN [ ^ ]函数,即:

Use the isNaN[^] function, namely:
if (isNaN(total)) total = 0;


请看我对这个问题的评论。



NaN(不是数字)是添加到浮点类型域的合法值之一,表示某些计算的非数字结果,例如除法0.0 / 0.0(它不会导致异常)但返回NaN)。这是IEEE-754标准的一部分。请参阅:

http://en.wikipedia.org/wiki/Floating_point [< a href =http://en.wikipedia.org/wiki/Floating_pointtarget =_ blanktitle =New Window> ^ ],

http://en.wikipedia.org/wiki/IEEE_754 [ ^ ]。



问题不是100%明确,而是一个这样的问题来源value是Javascropt调用 parseFloat(string)。它将返回NaN是不能以数字格式解释的字符串。请参阅: http://www.w3schools.com/jsref/jsref_parsefloat.asp [ ^ ]。



-SA
Please see my comment to the question.

NaN (not a number) is one of the legitimate values added to the domain of the floating-point type, to denote "not a number" result of some calculations, such as division 0.0/0.0 (it does not cause exception but returns NaN). This is the part of the IEEE-754 standard. Please see:
http://en.wikipedia.org/wiki/Floating_point[^],
http://en.wikipedia.org/wiki/IEEE_754[^].

The question is not 100% clear, but one source of such value is the Javascropt call parseFloat(string). It will return NaN is the string cannot be interpreted in a numeric format. Please see: http://www.w3schools.com/jsref/jsref_parsefloat.asp[^].

—SA


这篇关于如何将NaN更改为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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