M Maor Mishkin Jan 21, 2004 #1 I've changed from double to decimal calculations but I can't find a math library for decimal (mainly for sqrt), Thanks Maor
I've changed from double to decimal calculations but I can't find a math library for decimal (mainly for sqrt), Thanks Maor
M Morten Wennevik Jan 21, 2004 #2 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
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
? =?windows-1252?Q?Marcin_Grze=3Bbski?= Jan 21, 2004 #3 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 Click to expand... 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
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 Click to expand... 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