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 f, int i)
Round a number to "i" digits after the comma
int x = (int) (f * i);
float f2 = (float) x / (float) i;
return f2;
Stringround(float f, int n)
round
int d = (int) Math.pow(10, n);
return "" + ((int) (f * d)) / (float) d;
intround(float input)
round
return Math.round(input);
Stringround(float input)
round
df.setRoundingMode(RoundingMode.HALF_EVEN);
return df.format(input);
floatround(float number, int fractionalPartSize)
round
return (float) round((double) number, fractionalPartSize);
intround(float pX)
round
return floor(pX + 0.5f);
floatround(float Rval, int Rpl)
round
float p = (float) Math.pow(10, Rpl);
Rval = Rval * p;
float tmp = Math.round(Rval);
return (float) tmp / p;
Stringround(float Rval, int Rpl)
Rounds the Rval to the number of places in Rpl
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMaximumFractionDigits(Rpl);
return fmt.format(Rval);
intround(float v)
A cheaper version of Math#round that doesn't handle the special cases.
return (v < 0f) ? (int) (v - 0.5f) : (int) (v + 0.5f);
floatround(float val, int places)
round
return (float) round((double) val, places);