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

StringroundedSatisfaction(double value)
rounded Satisfaction
return String.format("%1$#.2f", value);
floatrounder(float value, int digits)
rounder
return Math.round(value * Math.pow(10, digits) + 0.5) / (float) Math.pow(10, digits);
floatroundf(float value)
roundf
float rest = value % 1f;
if (rest >= 0.5f) {
    value += 1f - rest;
} else {
    value -= rest;
return value;
longroundFileLength(long nbytes)
round File Length
if (nbytes <= 0)
    return 0;
else if (nbytes <= 512)
    return nbytes;
else if (nbytes % 512 == 0)
    return nbytes;
else
    return (int) (nbytes / 512 + 1) * 512;
...
floatroundFloat(float value, int afterDecimalPoint)
Rounds a double to the given number of decimal places.
float mask = (float) Math.pow(10, (float) afterDecimalPoint);
return (float) (Math.round(value * mask)) / mask;
floatroundFloatToPlace(float f, int place)
round Float To Place
if (place < 0)
    throw new IllegalArgumentException();
if (place > 9)
    throw new IllegalArgumentException();
long factor = (long) Math.pow(10, place);
return ((float) Math.round(f * factor)) / factor;
longroundFloatToUnitInverse(final float graphValue, final float graphUnit)
Round floating value to an inverse long value.
if (graphUnit < 1) {
    if (graphValue < 0) {
        final float value1 = graphValue / graphUnit;
        final float value2 = value1 - 0.5f;
        final long value3 = (long) (value2);
        return value3;
    } else {
        final float value1 = graphValue / graphUnit;
...
StringroundFormat(final int numPrec, final double number)
Round format.
return String.format("%." + numPrec + "f", number);
doubleRoundFullUp(double d)
Adds .5 and rounds the result...this should round up to the full integer anything <.4
return Math.round(.4 + d);
doubleroundHalfAway(double d)
round Half Away
if (d < 0) {
    d = Math.ceil(d - 0.5);
} else if (d > 0) {
    d = Math.floor(d + 0.5);
return d;