nehel nehel - 4 months ago 18
jQuery Question

toExponential() on Infinity number

I'm trying to get like first 7-8 numbers after digit on a number that is

Infinity
.

I.E.
console.log((4^3)/(3^3));
will result in an
Infinity
while the real result is
2.370370370...
. What I want is to get that number in
2.370370370e+-60
form.

I tried to make it with
result.toExponential(8);
but no effects so far. Any tips/answers would be appreciated.

Answer

In javascript, exponentiation is made by the Math.pow function. There is no inline operator like ^ (as in python with **).

You should instead compute

Math.pow(4, 3) / Math.pow(3, 3)

A part from that,

you were computing (4 XOR 3) / (3 XOR 3), which evaluates to 7 / 0, which is an Infinity.