如何检查数字是否评估为无穷大? [英] How do I check if a number evaluates to infinity?

查看:117
本文介绍了如何检查数字是否评估为无穷大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的Javascript计算(仅在IE下)根据用户的选择显示Infinity。

I have a series of Javascript calculations that (only under IE) show Infinity depending on user choices.

如何停止单词无限出现,例如,显示 0.0 而不是?

How does one stop the word Infinity appearing and for example, show 0.0 instead?

推荐答案

if (result == Number.POSITIVE_INFINITY || result == Number.NEGATIVE_INFINITY)
{
    // ...
}

您可以使用 isFinite 函数,取决于您要如何处理 NaN isFinite 如果您的电话号码 POSITIVE_INFINITY ,<$,则返回 false c $ c> NEGATIVE_INFINITY 或 NaN

You could possibly use the isFinite function instead, depending on how you want to treat NaN. isFinite returns false if your number is POSITIVE_INFINITY, NEGATIVE_INFINITY or NaN.

if (isFinite(result))
{
    // ...
}

这篇关于如何检查数字是否评估为无穷大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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