0

I have this formula on excel

=(1130000000000*F11^1.85)/(F19^1.85*(F13*(1-2/F15))^4.8655)

when

F11 = q
F19 = 150 (Constant)
F13 = d
F15 = sdr

I convert it to this

Math.round((1130000000000*Math.pow(q,1.85))/(Math.pow(150,1.85)*Math.pow(d*(1-2/sdr)),4.8655))

but the results are wrong

when

q = 120
d = 200
sdr = 17

the result should be 8.76 but I am getting long numbers

any help ? Thanks

Peril
  • 1,569
  • 6
  • 25
  • 42

2 Answers2

0

From YUI blog

JavaScript has a single number type: IEEE 754 Double Precision floating point. Having a single number type is one of JavaScript’s best features. Multiple number types can be a source of complexity, confusion, and error. A single type is simplifying and stabilizing. Unfortunately, a binary floating point type has some significant disadvantages. The worst is that it cannot accurately represent decimal fractions, which is a big problem because humanity has been doing commerce in decimals for a long, long time. There would be advantages to switching to a binary-based number system, but that is not going to happen. As a consequence, 0.1 + 0.2 === 0.3 is false, which is the source of a lot of confusion.

http://www.yuiblog.com/blog/2009/03/10/when-you-cant-count-on-your-numbers/

Frank Dai
  • 50
  • 5
-1

Completely ignore my previous answer, although it is a problem which you will definitely encounter should you continue with these large numbers, your actual issue is a misplaced bracket in your code. If you use this (simply replaced variable names with values):

Math.round((1130000000000*Math.pow(120,1.85))/(Math.pow(150,1.85)*Math.pow((200*(1-2/17)),4.8655)))

It returns 9 (a rounded 8.76), the bracket you misplaced is around the 1-2 mark.

For future reference, the largest number Javascript can comprehend without fault is +/- 9007199254740992.

References:

What is JavaScript's highest integer value that a Number can go to without losing precision?

ECMA-262 - The Number Type

Community
  • 1
  • 1
James Hunt
  • 2,448
  • 11
  • 23