0

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?

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

nihulus
  • 1,475
  • 4
  • 24
  • 46

3 Answers3

0

It's not too long to display. If you get Inf then you can't do anything with it other than know that it is something larger than the maximum possible value. This is the behavior of IEEE floating point numbers that are used in JavaScript.

rsp
  • 107,747
  • 29
  • 201
  • 177
0

Probably the cause for this Infinity is a division by zero, not a big number.

iurisilvio
  • 4,868
  • 1
  • 30
  • 36
0

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]

See also the official ECMA Description on Numbers

Lorenz Lo Sauer
  • 23,698
  • 16
  • 85
  • 87