Java Utililty Methods Double Number Truncate

List of utility methods to do Double Number Truncate

Description

The list of methods to do Double Number Truncate are organized into topic(s).

Method

doubletruncate(double oldVal, double newMin, double newMax)
truncate
double retVal = oldVal;
if (retVal < newMin) {
    retVal = newMin;
if (retVal > newMax) {
    retVal = newMax;
return retVal;
...
doubletruncate(double value, double precision)
Utility method used to truncate a double to the given precision.
double result;
precision = Math.pow(10, precision);
if (value > 0) {
    result = Math.floor(value * precision) / precision;
} else {
    result = Math.ceil(value * precision) / precision;
return result;
...
doubletruncate(double value, int precision)
truncate
String str = Double.toString(value);
String precisionstr = str.substring(str.indexOf('.') + 1);
if (precisionstr.length() <= precision) {
    return value;
} else {
    long tmp = Math.round(value * Math.pow(10, precisionstr.length()));
    for (int i = 0; i < precisionstr.length() - precision - 1; i++) {
        tmp /= 10;
...
doubletruncate(double value, int truncation)
truncate
return Math.floor(value * truncation) / truncation;
inttruncate(double x)
truncate
int res;
if (x > 255)
    res = 255;
else if (x < 0)
    res = 0;
else
    res = (int) x;
return res;
...
doubletruncate(double x)
Returns the value of the integer of highest magnitude (farthest from zero) whose absolute value is at most that of x.
return x > 0.0 ? Math.floor(x) : Math.ceil(x);
doubletruncate(double x, double gran)
truncate
return Math.round(x / gran) * gran;
double[]truncate(double[] arr, int m)
truncate
double[] tArr = new double[m];
System.arraycopy(arr, 0, tArr, 0, m);
return tArr;
doubletruncate(final double value, final double min, final double max)
truncate
return Math.min(Math.max(value, min), max);
doubletruncate(final double value, final double precision)
Truncate a value to the specified precision.
double f, v;
boolean b;
if (precision <= 0.0d)
    return value;
if (value == 0.0d)
    return 0.0d;
if (value < 0.0d) {
    v = -value;
...