Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
3.20/5 (3 votes)
See more:
How do I convert a float array to a double array?


This does not work:
C#
float[,] resultArray2 = new float[354, 354];
double[,] resultArray3 = new double[354, 354];
resultArray2 = resultArray3;
Posted
Updated 14-Dec-15 3:13am
v2

Hello

C#
float[,] resultArray2 = new float[354, 354];

double[,] resultArray3 = new double[354, 354];


for (int i = 0; i < resultArray2.GetLength(0); i++)
{
    for (int j = 0; j < resultArray2.GetLength(1); j++)
    {
        resultArray3[i, j] = resultArray2[i, j];
    }
}
 
Share this answer
 
Comments
ProEnggSoft 18-Mar-12 20:18pm    
What OP has asked is to convert Double array to Float array. As Double cannot be converted implicitly, resultArray2[i,j] = (float)resultArray3[i,j]; is to be used in the loop.
As the logic is correct. My 5!
Shahin Khorshidnia 19-Mar-12 5:51am    
Thank you very much.
Yes, but OP wants to convert float to double and it doesn't need :
resultArray2[i,j] = (double)resultArray3[i,j];
Thanks again.
C#
public static double[] convertToDouble(float[] inputArray)
{
    if (inputArray== null)
        return null; 

    double[] output = new double[inputArray.length];
    for (int i = 0; i < inputArray.length; i++)
        output[i] = inputArray[i];

    return output;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900