Java Round Float Variable

A nifty tool to round off a float variable to the nearest decimal place.

public static float roundFloat(float f, int decimals) {
  String s = number2str((Double.valueOf(String.valueOf(f))).doubleValue(), decimals);
  Float ff = Float.valueOf(replaceString(s, ",", ""));
  return ff.floatValue();

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *