Java Utililty Methods Float Number Round

List of utility methods to do Float Number Round

  1. HOME
  2. Java
  3. F
  4. Float Number Round

Description

The list of methods to do Float Number Round are organized into topic(s).

Method

int round(final float a)
Round a
return (int) (a + Math.signum(a) * 0.5f);
int round(final float f)
round
return (int) (f > 0 ? f + 0.5F : f - 0.5F);
int round(final float val)
round
return floor(val + 0.5f);
int round(final float value)
round
return (int) (value + (0.5f * Math.signum(value)));
float round(final float x, final float roundFactor)
Computes a rounded value for the given rounding factor.
return (float) Math.round(x * roundFactor) / roundFactor;
int round(float a)
Rounds the number to the closest integer
return Math.round(a);
float round(float amount, int cent)
round
if (cent <= 0) {
 throw new IllegalArgumentException("cent must be greater than 0");
int roundAmount = Math.round(amount * 100.0f);
int x = roundAmount % cent;
int discount = 0;
if (x > cent / 2.0f) {
 discount = cent - x;
...
int round(float axisValue)
round
if (Math.abs(axisValue) < 0.4f) {
 return 0;
return (int) Math.signum((int) (100 * axisValue));
int round(float d)
Ends up being a bit faster than Math#round(float) .
return (int) (d + (d < 0.0f ? -0.5f : 0.5f));
float round(float f, int dp)
round
float pow = (float) Math.pow(10, dp);
float round = Math.round(f * pow);
return round / pow;


AltStyle によって変換されたページ (->オリジナル) /