skip to Main Content

So i’m doing some math formula, where on second part this calculation happens
(x + 1)^1.06 where x stands for 1 on execution. If we check calculator it will give something like ~2.08, but printing number in js says it equals to 3. How it even rounded it to 3.
Also i was looking for that auto rounding, but i didn’t find anything. Sorry if this easy issue i’m now just learning JS.

I tryed using parseFloat(), some other things, but it always round this formula(with x=1) to 3. I don’t get it

2

Answers


  1. That is because ^ is not the exponent operator. It is the Bitwise XOR operator. The exponent operator in Javascript is **. So do this: (x + 1)**1.06, to get the result you want.

    Login or Signup to reply.
  2. Try this instead
    ans=Math.pow(2, 1.06)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search