Java Float Number Round round(float x)

Here you can find the source of round(float x)

Description

Returns the closest integer to the specified float.

License

Apache License

Declaration

static public int round(float x) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static private final int BIG_ENOUGH_INT = 16 * 1024;
    static private final double BIG_ENOUGH_ROUND = BIG_ENOUGH_INT + 0.5f;

    /**/*from  w ww .  j a  va2s. co m*/
     * Returns the closest integer to the specified float. This method will only
     * properly round floats from -(2^14) to (Float.MAX_VALUE - 2^14).
     */
    static public int round(float x) {
        return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
    }
}

Related

  1. round(float Rval, int Rpl)
  2. round(float v)
  3. round(float val, int places)
  4. round(float value, float epsilon)
  5. round(float value, float snap)
  6. round(float x, float y)
  7. roundTo(float num, int dp)