Java Integer to Float convertIntToFloat(final int[] intValues)

Here you can find the source of convertIntToFloat(final int[] intValues)

Description

convert Int To Float

License

Open Source License

Declaration

public static float[] convertIntToFloat(final int[] intValues) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2005, 2016 Wolfgang Schramm and Contributors
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation version 2 of the License./*from  w w  w  .ja  v  a  2  s  .  c  o m*/
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *******************************************************************************/

public class Main {
    public static float[] convertIntToFloat(final int[] intValues) {

        if (intValues == null) {
            return null;
        }

        if (intValues.length == 0) {
            return new float[0];
        }

        final float[] floatValues = new float[intValues.length];

        for (int valueIndex = 0; valueIndex < intValues.length; valueIndex++) {
            floatValues[valueIndex] = intValues[valueIndex];
        }

        return floatValues;
    }

    public static float[][] convertIntToFloat(final int[][] intValues) {

        if (intValues == null) {
            return null;
        }

        if (intValues.length == 0 || intValues[0].length == 0) {
            return new float[0][0];
        }

        final float[][] floatValues = new float[intValues.length][intValues[0].length];

        for (int outerIndex = 0; outerIndex < intValues.length; outerIndex++) {

            final int[] intOuterValues = intValues[outerIndex];
            final float[] floatOuterValues = floatValues[outerIndex];

            for (int innerIndex = 0; innerIndex < intOuterValues.length; innerIndex++) {
                floatOuterValues[innerIndex] = intOuterValues[innerIndex];
            }
        }

        return floatValues;
    }
}

Related

  1. convertIntToFloat(int arr[])
  2. intToFloat(int integer)
  3. intToFloat(int[] values)
  4. IntToFloat(long x)