Java Double Number Truncate truncateNaN(double[] values)

Here you can find the source of truncateNaN(double[] values)

Description

truncates the given array by removing all fields at the end that contain the given value, e.g., {0,1,0,2,3,0,0} => {0,1,0,2,3} for value=0

License

Open Source License

Parameter

Parameter Description
values array to truncate
value value to remove from the end of the array

Return

truncated array

Declaration

public static double[] truncateNaN(double[] values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w ww . ja v a 2  s  .c o  m*/
     * truncates the given array by removing all fields at the end that contain
     * the given value, e.g., {0,1,0,2,3,0,0} => {0,1,0,2,3} for value=0
     * 
     * @param values
     *            array to truncate
     * @param value
     *            value to remove from the end of the array
     * @return truncated array
     */
    public static double[] truncateNaN(double[] values) {
        if (!Double.isNaN(values[values.length - 1])) {
            return values;
        }
        int index = values.length - 1;
        for (int i = values.length - 1; i >= 0; i--) {
            if (!Double.isNaN(values[i])) {
                break;
            }
            index--;
        }
        double[] valuesNew = new double[index + 1];
        System.arraycopy(values, 0, valuesNew, 0, index + 1);
        return valuesNew;
    }
}

Related

  1. truncateDigits(double[][] input, int numberDigits)
  2. truncateDouble(final Double value)
  3. truncateDoubleDecimals(double x1, int num)
  4. truncateDoubleToInt(double p_76140_0_)
  5. truncateDoubleToInt(double x)
  6. truncateNoSciNotation(double d, int decimals)
  7. truncateRows(double[][] matrix, int nCols)
  8. truncateToTwoDecimals(double value)
  9. truncDouble(double val)