Java Float Number Create toFloat(int[] array)

Here you can find the source of toFloat(int[] array)

Description

1-D Integer array to float array.

License

BSD License

Parameter

Parameter Description
array Integer array.

Return

Float array.

Declaration

public static float[] toFloat(int[] array) 

Method Source Code

//package com.java2s;
// under the BSD license. The original license terms are given below:

public class Main {
    /**//from w w w. ja  v a2s .com
     * 1-D Integer array to float array.
     * @param array Integer array.
     * @return Float array.
     */
    public static float[] toFloat(int[] array) {
        float[] n = new float[array.length];
        for (int i = 0; i < array.length; i++) {
            n[i] = (float) array[i];
        }
        return n;
    }

    /**
     * 2-D Integer array to float array.
     * @param array Integer array.
     * @return Float array.
     */
    public static float[][] toFloat(int[][] array) {
        float[][] n = new float[array.length][array[0].length];
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                n[i][j] = (float) array[i][j];
            }
        }
        return n;
    }

    /**
     * 1-D Double array to float array.
     * @param array Double array.
     * @return Float array.
     */
    public static float[] toFloat(double[] array) {
        float[] n = new float[array.length];
        for (int i = 0; i < array.length; i++) {
            n[i] = (float) array[i];
        }
        return n;
    }

    /**
     * 2-D Double array to float array.
     * @param array Double array.
     * @return Float array.
     */
    public static float[][] toFloat(double[][] array) {
        float[][] n = new float[array.length][array[0].length];
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                n[i][j] = (float) array[i][j];
            }
        }
        return n;
    }
}

Related

  1. toFloat(int colorComponent)
  2. toFloat(int hbits)
  3. toFloat(int majorVersion, int minorVersion)
  4. toFloat(int value)
  5. toFloat(int x)
  6. toFloat(long intPart, long decimalPart, long decimalPlaces)
  7. toFloat(Number value)
  8. toFloat(Object _inStrObj)
  9. toFloat(Object anObj)