Java Utililty Methods Number Round

List of utility methods to do Number Round

Description

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

Method

double[]roundMinAndMax(double min, double max, int tickCount)
round Min And Max
double roundingUnit;
boolean minGreaterThanZero = min >= 0;
boolean maxGreaterThanZero = max > 0;
int topTicks;
int botTicks;
double tempMax;
double tempMin;
int units = tickCount - 1;
...
StringroundMultiplier(double n)
round Multiplier
if (n >= 0.9) {
    n = Math.round(n);
    if (n >= 10) { 
        n = Math.round(n / 10) * 10;
    if (n >= 100) { 
        n = Math.round(n / 100) * 100;
    if (n >= 1000) { 
        n = Math.round(n / 1000) * 1000;
    return Integer.toString((int) n);
} else {
    String base = roundMultiplier(1. / n);
    if (base.equals("1"))
        return base;
    else
        return "1/" + base;
doubleroundNearest(double v, double target)
Rounds a value to the nearest multiple of a target.
target = Math.abs(target);
if (v >= 0) {
    return target * Math.floor((v + 0.5f * target) / target);
} else {
    return target * Math.ceil((v - 0.5f * target) / target);
StringroundNicely(double dbl)
round Nicely
long rounded = Math.round((dbl * 100.0));
String result = String.valueOf(((double) rounded) / 100.0);
if (dbl < 10) {
    result = String.valueOf(Math.round(dbl * 100.0) / 100.0);
} else if (dbl < 100) {
    result = String.valueOf(Math.round(dbl * 10.0) / 10.0);
} else {
    result = String.valueOf(((long) dbl));
...
doubleroundNumber(double rowNumber, int roundingPoint)
round Number
double base = Math.pow(10D, roundingPoint);
return (double) Math.round(rowNumber * base) / base;
doubleroundNumber(double theNumber, int places)
round Number
double placesDouble = Math.pow(10, places);
return Math.round(theNumber * placesDouble) / placesDouble;
floatroundNumber(float input, float rounding)
round Number
int o = (int) (input * rounding);
return o / rounding;
StringroundNumber(String n)
round Number
String res = n;
if (n != null) {
    double dbl = Double.parseDouble(n);
    double d = Math.round(dbl * Math.pow(10, 3.0)) / Math.pow(10, 3.0);
    res = Double.toString(d);
return res;
StringroundNumberTo(double value, int decimals)
Rounds numbers down at the given decimal.
return "" + Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals);
doubleroundNumberToDouble(double value, int decimals)
round Number To Double
return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals);