sqrt operation for decimal

  • Thread starter Thread starter Maor Mishkin
  • Start date Start date
M

Maor Mishkin

I've changed from double to decimal calculations but I can't find a math
library for decimal (mainly for sqrt),
Thanks Maor
 
Since Math.Sqrt only uses double you will have to cast it to and from
double.

decimal d = 0.0000000000000000000000000002m;
decimal e = (decimal)Math.Sqrt((double)d);

// e == 0,000000000000014142135623731
 
Maor said:
I've changed from double to decimal calculations but I can't find a math
library for decimal (mainly for sqrt),
Thanks Maor

Hi Maor,

I'm affraid that Math.Sqrt is only choice...
and it works with double numbers only.
You can write your own DecimalSqrt function:

public static decimal Sqrt(decimal val) {
return new Decimal(Math.Sqrt((double) val));
}

Regards

Marcin
 
Back
Top