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

longtrunc(double value)
Truncates the specified value.
return (long) value;
doubletrunc(double value, double threshold)
trunc
return Math.max(Math.min(value, threshold), -threshold);
doubletrunc(double value, int dp)
Truncates a double to given decimal digits
double factor;
factor = Math.pow(10, dp);
return Math.floor(value * factor) / factor;
doubletrunc(double value, int len)
trunc
if (Double.isNaN(value)) {
    return Double.NaN;
if (Double.isInfinite(value)) {
    return value;
double p = Math.pow(10, len);
if (value > 0) {
...
doubletrunc(double x)
Return the integer portion of a double as a double.
long lx = (long) x;
return (double) lx;
doubletrunc(double x)
trunc
return x - x % 1;
doubletrunc(double x, double y)
Truncate x down to the nearest y.
return y * Math.floor((x + .00001) / y);
doubletrunc4(Double number)
trunc
return Math.round(number * Math.pow(10, 4)) / Math.pow(10, 4);
doubletruncate(double d)
truncate
if (d < 0)
    return -1 * Math.floor(d * -1);
else
    return Math.floor(d);
doubletruncate(double fullVal, int digits)
Given a double, zeros all portions of the fraction past a given number of digits.
double factor = Math.pow(10.0, (double) digits);
int itmp = (int) (factor * fullVal);
return ((double) itmp) / factor;