0

有谁知道如何将二维数组从 double 转换为 float 我有以下内容:

double [][] matrix = new double[width][height];

我想将变量 data 中的数据转换为 Flaot,所以我有一个新变量,如下所示:

float [][] floatmatrix = new float[width][height];

我试过铸造,但它是不允许的,例如

float[][] data = (float[][]) result;
4

1 回答 1

2

您需要逐项复制它(在两个嵌套循环中):

    float[][] floatmatrix = new float[width][height];
    for (w = 0; width > w; w++) {
        for (h = 0; height > h; h++) {
            floatmatrix[w][h] = (float) matrix[w][h];
        }
    }
于 2013-02-02T20:28:23.443 回答