如果它是NaN使其为0 [英] if it's NaN make it 0

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

问题描述

嘿所有,

ph_area_1_appraiserscore =

isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;


这是唯一的怎么说呢?


谢谢,

rodchar

解决方案

这个顺便说一句是一个javascript问题。


" rodchar"写道:


hey all,

ph_area_1_appraiserscore =

isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;


这是唯一的说法吗?


谢谢,

rodchar


似乎很好。有什么问题?


另一种选择是首先避免使用NaN ......


-

Patrice


" rodchar" < ro ***** @discusss.microsoft.comaécritdansle message de

groupe de discussion: 13 ******************** **************@microsoft.com ...


这是一个javascript问题。


" rodchar"写道:


>嘿所有,
ph_area_1_appraiserscore =
isNaN(ph_area_1_appraiserscore)?0:ph_area_1_appra iserscore;

这是唯一的说法吗?

感谢,
rodchar



< blockquote>

" rodchar" < ro ***** @ discussion.microsoft.com写信息

新闻:B6 *********************** *********** @ microsof t.com ...


hey all,

ph_area_1_appraiserscore =

isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;


这是唯一的说法吗?



是的,但您可以随时放置一个函数来保持代码整洁。我
会为Number原型添加一个方法: -

Number.prototype.valueOrZero = function()

{return isNaN(this) ? 0:this.valueOf();}

现在你可以使用: -


ph_area_1_appraiserscore = ph_area_1_appraiserscore.valueOrZero();

哪个看起来会更好(只是稍微因为变量名是这样的,所以
很长)。


当然这可以在源头完成最可能的NaN来源

是一个解析。例如


ph_area_1_appraiserscore = parseInt(sSomeSource).valueOrZero();

BTW你有其他变量以前缀ph_area_1_开头吗?

你还有一个更大范围的变量,它们以

ph_area_n_开头,其中n来自一组整数?


如果是这样的话那说些什么?如果不是为什么这样一个满口的
变量名?


-

Anthony Jones - MVP ASP /ASP.NET


hey all,
ph_area_1_appraiserscore =
isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;

is this the only way to say this?

thanks,
rodchar

解决方案

this is a javascript question by the way.

"rodchar" wrote:

hey all,
ph_area_1_appraiserscore =
isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;

is this the only way to say this?

thanks,
rodchar


Seems good. What is the problem ?

Another option would to avoid NaN in first place...

--
Patrice

"rodchar" <ro*****@discussions.microsoft.coma écrit dans le message de
groupe de discussion : 13**********************************@microsoft.com...

this is a javascript question by the way.

"rodchar" wrote:

>hey all,
ph_area_1_appraiserscore =
isNaN(ph_area_1_appraiserscore)?0:ph_area_1_appra iserscore;

is this the only way to say this?

thanks,
rodchar




"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:B6**********************************@microsof t.com...

hey all,
ph_area_1_appraiserscore =
isNaN(ph_area_1_appraiserscore)?0:ph_area_1_apprai serscore;

is this the only way to say this?

Yes but you could always place in a function to keep your code tidy. I
would add a method to the Number prototype:-
Number.prototype.valueOrZero = function()
{ return isNaN(this) ? 0 : this.valueOf();}
Now you could use:-

ph_area_1_appraiserscore = ph_area_1_appraiserscore.valueOrZero();

Which would look better (only slightly because the variable name is so
long).

Of course this could be done at source since the most likely source of a NaN
is a parse. E.g.

ph_area_1_appraiserscore = parseInt(sSomeSource).valueOrZero();
BTW do you have other variables that begin with the prefix ph_area_1_ ?
Also do you have an even greater range of variables that begin with
ph_area_n_ where n is from a set of integers?

If so isn''t that telling something? If not why such a mouthfull of a
variable name?


--
Anthony Jones - MVP ASP/ASP.NET


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

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