Java Double Number Truncate truncateDigits(double[][] input, int numberDigits)

Here you can find the source of truncateDigits(double[][] input, int numberDigits)

Description

truncate Digits

License

LGPL

Declaration

public static String[][] truncateDigits(double[][] input, int numberDigits) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static String[][] truncateDigits(double[][] input, int numberDigits) {
        String[][] result = new String[input.length][];
        int indexDot = -1;
        String integerPart = null, decimalPart = null, dot = ".";
        String wholePart = null;/*from   w  ww.  j a va2s . c o m*/
        //int maxNumberDigit = 0;
        for (int i = 0; i < input.length; i++) {
            result[i] = new String[input[i].length];
            for (int j = 0; j < input[i].length; j++) {

                System.out.println("input[" + i + "][" + j + "] = " + input[i][j]);

                wholePart = input[i][j] + "";
                indexDot = (wholePart).indexOf(dot);
                if (indexDot >= 0) {
                    integerPart = wholePart.substring(0, indexDot);
                    try {
                        decimalPart = wholePart.substring(indexDot + 1, indexDot + 1 + numberDigits);
                    } catch (Exception e) {
                        decimalPart = wholePart.substring(indexDot + 1, wholePart.length());

                        //decimalPart = wholePart.substring(indexDot + 1, );
                    }
                    result[i][j] = integerPart + dot + decimalPart;
                } else {
                    result[i][j] = input[i][j] + "";
                }
            }
        }
        return result;
    }
}

Related

  1. truncate(double[] arr, int m)
  2. truncate(final double value, final double min, final double max)
  3. truncate(final double value, final double precision)
  4. truncate2decimals(double x)
  5. truncateDigits(double input, int numberDigits)
  6. truncateDouble(final Double value)
  7. truncateDoubleDecimals(double x1, int num)
  8. truncateDoubleToInt(double p_76140_0_)
  9. truncateDoubleToInt(double x)