0

I have a calculation:

 (22,582 / 10,000)^1/15 - 1

In C# I am using like this:

double i = Math.Pow(2.2582,1/15) - 1;
Response.Write(i);

But everytime it returns me 0 in i. I know (1/15) is making some disturbance in the calculation, so to solve this I used (.067) in place of (1/15) which gives me result 0.0560927980835855, but I am still far away from my actual result. Can somebody please tell the right approach.

4

2 回答 2

2

The first calculation should be:

(22.582d / 10.000d) * (1.0d/15.0d) - 1.0d

You use the "d" in literals to tell the compiler that the number should be a double. If you don't use it the compiler thinks that 1/15 is two integers divided resulting in 0.

So the last calculation should be:

double i = Math.Pow(2.2582d, 1.0d/15.0d) - 1.0d;
Response.Write(i);

This means that:

1/15 = 0

and

1.0d/15.0d = 0.06666667
于 2013-09-12T10:11:27.883 回答
0

Here 1 and 15 are considered as integers and were calculated to find the integer result 1/15 =0; not the double result. Try using 1f/15f instead of 1/15

于 2013-09-12T10:11:53.900 回答