List of utility methods to do Float Number Round
float | round(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; |
String | round(float f, int n) round int d = (int) Math.pow(10, n); return "" + ((int) (f * d)) / (float) d; |
int | round(float input) round return Math.round(input);
|
String | round(float input) round df.setRoundingMode(RoundingMode.HALF_EVEN);
return df.format(input);
|
float | round(float number, int fractionalPartSize) round return (float) round((double) number, fractionalPartSize); |
int | round(float pX) round return floor(pX + 0.5f);
|
float | round(float Rval, int Rpl) round float p = (float) Math.pow(10, Rpl); Rval = Rval * p; float tmp = Math.round(Rval); return (float) tmp / p; |
String | round(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);
|
int | round(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); |
float | round(float val, int places) round return (float) round((double) val, places); |