List of utility methods to do Float Number Round
float | round(float value, float epsilon) discretizes values to nearest finite resolution real number determined by epsilon spacing return clamp(Math.round(value / epsilon) * epsilon);
|
float | round(float value, float snap) round if (snap == 0.0f) return value; return ((int) (value / snap)) * snap; |
int | round(float x) Returns the closest integer to the specified float. return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT; |
float | round(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); |
float | roundTo(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); ... |