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...