List of utility methods to do Double Number Truncate
double | truncate2decimals(double x) truncatedecimals return Math.floor(x * 100) / 100;
|
String | truncateDigits(double input, int numberDigits) CODE EXAMPLE int indexDot = -1; String integerPart = null, decimalPart = null, dot = "."; String wholePart = null; String result = null; wholePart = input + ""; indexDot = (wholePart).indexOf(dot); if (indexDot >= 0) { integerPart = wholePart.substring(0, indexDot); ... |
String[][] | truncateDigits(double[][] input, int numberDigits) truncate Digits String[][] result = new String[input.length][]; int indexDot = -1; String integerPart = null, decimalPart = null, dot = "."; String wholePart = null; 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]); ... |
Double | truncateDouble(final Double value) Truncate the decimal part of a double to keep only 2 decimals. if (value == null) { return null; return Double.valueOf(truncate(value)); |
double | truncateDoubleDecimals(double x1, int num) truncate Double Decimals double mult1 = Math.pow(10, num); int mult = (int) mult1; double y1; double y2; if (x1 > 0) { y1 = Math.floor(x1 * mult); y2 = y1 / (mult); } else { ... |
int | truncateDoubleToInt(double p_76140_0_) returns par0 cast as an int, and no greater than Integer.MAX_VALUE-1024 return (int) (p_76140_0_ + 1024.0D) - 1024; |
int | truncateDoubleToInt(double x) truncate Double To Int return (int) Math.floor(x); |
double[] | truncateNaN(double[] values) 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 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; |
String | truncateNoSciNotation(double d, int decimals) truncate No Sci Notation return String.format("%." + decimals + "f", d); |
double[][] | truncateRows(double[][] matrix, int nCols) copy only first nCols of matrix final int nRows = matrix.length; final double[][] result = new double[nRows][nCols]; for (int row = 0; row < nRows; row++) { System.arraycopy(matrix[row], 0, result[row], 0, nCols); return result; |