Javascript无限对象 [英] Javascript Infinity Object

查看:76
本文介绍了Javascript无限对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在计算函数请求/秒的平均值,显然结果数有时太长所以它显示为Infinity,有没有办法将它舍入以便它只显示一个数字?或者在Infinity上做一个sleep()/ wait()?

I'm caclulating the mean value of a function's request/sec, appearently the result number sometimes is too long so it displays as Infinity, is there a way to round it so it show a number only? Or make a sleep()/wait() while it's on Infinity?

确切地说,我正在监视图表上的req / sec,当它是无穷大的时候行向上不是零

well to be exactly, im monitoring req/sec on a graph, when it's infinity the line goes up not towards zero

推荐答案

您很可能无意中除以零。

You are most likely unintentionally dividing by zero.

var num = 1/0;
console.log(num);
//>Infinity

有条件地检查除数是否为空。

Conditionally check that the divisor is not null.

您可以按如下方式检查整数的最大值:

You can check the maximum value of an integer as follows:

console.log([Number.MAX_VALUE, Number.MIN_VALUE]);
//>[1.7976931348623157e+308, 5e-324]

参见有关数字的官方 ECMA说明

这篇关于Javascript无限对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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