Java Utililty Methods Float Number Round

List of utility methods to do Float Number Round

Description

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

Method

intround(final float a)
Round a
return (int) (a + Math.signum(a) * 0.5f);
intround(final float f)
round
return (int) (f > 0 ? f + 0.5F : f - 0.5F);
intround(final float val)
round
return floor(val + 0.5f);
intround(final float value)
round
return (int) (value + (0.5f * Math.signum(value)));
floatround(final float x, final float roundFactor)
Computes a rounded value for the given rounding factor.
return (float) Math.round(x * roundFactor) / roundFactor;
intround(float a)
Rounds the number to the closest integer
return Math.round(a);
floatround(float amount, int cent)
round
if (cent <= 0) {
    throw new IllegalArgumentException("cent must be greater than 0");
int roundAmount = Math.round(amount * 100.0f);
int x = roundAmount % cent;
int discount = 0;
if (x > cent / 2.0f) {
    discount = cent - x;
...
intround(float axisValue)
round
if (Math.abs(axisValue) < 0.4f) {
    return 0;
return (int) Math.signum((int) (100 * axisValue));
intround(float d)
Ends up being a bit faster than Math#round(float) .
return (int) (d + (d < 0.0f ? -0.5f : 0.5f));
floatround(float f, int dp)
round
float pow = (float) Math.pow(10, dp);
float round = Math.round(f * pow);
return round / pow;