Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert Decimal array to Double array

What's an efficient and hopefully elegant incantation to convert decimal[] to double[]? I'm working with some fairly large arrays.

like image 353
I. J. Kennedy Avatar asked Nov 14 '10 01:11

I. J. Kennedy


2 Answers

double[] doubleArray = Array.ConvertAll(decimalArray, x => (double)x);
like image 192
LukeH Avatar answered Nov 03 '22 21:11

LukeH


You also can use and extension classes similar to this one

public static class ArrayExtension
{

   public static double[] ToDouble(this float[] arr) => 
                                    Array.ConvertAll(arr, x => (double)x);

}

Then:

double[] doubleArr = decimalArr.ToDouble();
like image 39
Victor Avatar answered Nov 03 '22 21:11

Victor