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

floatround(float value, float epsilon)
discretizes values to nearest finite resolution real number determined by epsilon spacing
return clamp(Math.round(value / epsilon) * epsilon);
floatround(float value, float snap)
round
if (snap == 0.0f)
    return value;
return ((int) (value / snap)) * snap;
intround(float x)
Returns the closest integer to the specified float.
return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
floatround(float x, float y)
Returns the given number rounded to the second number (rounding to arbitrary floating values).
return y * (int) ((x + sign(x) * y / 2) / y);
floatroundTo(float num, int dp)
Round the value to the specified number of decimal points.
StringBuilder sb = new StringBuilder();
sb.append("#");
if (dp > 0)
    sb.append(".");
for (int i = 0; i < dp; i++)
    sb.append("#");
DecimalFormat df = new DecimalFormat(sb.toString());
df.setRoundingMode(RoundingMode.HALF_UP);
...