Hello,
I saw this problem today.
I used to calculate this: varX = Math.Pow(varx, 1/3);
Everytime I get only an integer that is completly wrong!
But if I use this: varX = Math.Pow(varx, 0.333333);
Then the result is allright...
What is wrong with this function?
I can't express 1/3 as a double number cause it's endless.
Please help me...
Loading
FroglegPosted Mar 22, 2011, 8:29 AM
1:
double dd = Math.Round(((double)1 / (double)3),5);
2: or
decimal dd = Decimal.Round((decimal)1 / (decimal)3,5);
varX = Math.Pow(varx, dd);
Sascha BPosted Mar 22, 2011, 9:27 AM
I think it is more "correctly" than Froglegs round workaround.
Thanks
VulpesPosted Mar 22, 2011, 9:20 AM
1.0/3 or 1D/3
or decimal arithmetic with:
1M/3
As long as at least one operand is of type double or decimal, then this will avoid integer arithmetic from being used.
FroglegPosted Mar 22, 2011, 8:36 AM
Sascha BPosted Mar 22, 2011, 8:33 AM
And it WORKS! O_o
It can't calculate with endless numbers, can it?
Many thanks