Tabnine Logo
Math.round
Code IndexAdd Tabnine to your IDE (free)

How to use
round
method
in
java.lang.Math

Best Java code snippets using java.lang.Math.round (Showing top 20 results out of 40,203)

origin: PhilJay/MPAndroidChart

@Override
public String getFormattedValue(float value) {
  int index = Math.round(value);
  if (index < 0 || index >= mValueCount || index != (int)value)
    return "";
  return mValues[index];
}
origin: stackoverflow.com

 value = 5.5

Math.floor(value) //  5
Math.ceil(value)  //  6
Math.round(value) //  6
Math.trunc(value) //  5
parseInt(value)   //  5
~~value           //  5
value | 0         //  5
value >> 0        //  5
value >>> 0       //  5
value - value % 1 //  5
origin: stackoverflow.com

 value = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1

Math.floor(value) // -900719925474100
Math.ceil(value)  // -900719925474099
Math.round(value) // -900719925474099
Math.trunc(value) // -900719925474099
parseInt(value)   // -900719925474099
value | 0         // -858993459
~~value           // -858993459
value >> 0        // -858993459
value >>> 0       //  3435973837
value - value % 1 // -900719925474099
origin: stackoverflow.com

 value = -5.5

Math.floor(value) // -6
Math.ceil(value)  // -5
Math.round(value) // -5
Math.trunc(value) // -5
parseInt(value)   // -5
value | 0         // -5
~~value           // -5
value >> 0        // -5
value >>> 0       // 4294967291
value - value % 1 // -5
origin: stackoverflow.com

 var intvalue = Math.floor( floatvalue );
var intvalue = Math.ceil( floatvalue ); 
var intvalue = Math.round( floatvalue );

// `Math.trunc` was added in ECMAScript 6
var intvalue = Math.trunc( floatvalue );
origin: stackoverflow.com

 value = Number.MAX_SAFE_INTEGER/10 // 900719925474099.1

Math.floor(value) //  900719925474099
Math.ceil(value)  //  900719925474100
Math.round(value) //  900719925474099
Math.trunc(value) //  900719925474099
parseInt(value)   //  900719925474099
value | 0         //  858993459
~~value           //  858993459
value >> 0        //  858993459
value >>> 0       //  858993459
value - value % 1 //  900719925474099
origin: stackoverflow.com

 public static double round(double value, int places) {
  if (places < 0) throw new IllegalArgumentException();

  long factor = (long) Math.pow(10, places);
  value = value * factor;
  long tmp = Math.round(value);
  return (double) tmp / factor;
}
origin: google/guava

/**
 * Computes the optimal k (number of hashes per element inserted in Bloom filter), given the
 * expected insertions and total number of bits in the Bloom filter.
 *
 * <p>See http://en.wikipedia.org/wiki/File:Bloom_filter_fp_probability.svg for the formula.
 *
 * @param n expected insertions (must be positive)
 * @param m total number of bits in Bloom filter (must be positive)
 */
@VisibleForTesting
static int optimalNumOfHashFunctions(long n, long m) {
 // (m / n) * log(2), but avoid truncation due to division!
 return Math.max(1, (int) Math.round((double) m / n * Math.log(2)));
}
origin: libgdx/libgdx

private void storeKerningOffset (int firstGlyphCode, int secondGlyphCode, int offset) {
  // Scale the offset values using the font size.
  int value = Math.round(offset * scale);
  if (value == 0) {
    return;
  }
  int key = (firstGlyphCode << 16) | secondGlyphCode;
  kernings.put(key, value);
}
origin: libgdx/libgdx

private void storeKerningOffset (int firstGlyphCode, int secondGlyphCode, int offset) {
  // Scale the offset values using the font size.
  int value = Math.round(offset * scale);
  if (value == 0) {
    return;
  }
  int key = (firstGlyphCode << 16) | secondGlyphCode;
  kernings.put(key, value);
}
origin: libgdx/libgdx

@Override
public void update (int screenWidth, int screenHeight, boolean centerCamera) {
  Vector2 scaled = scaling.apply(getWorldWidth(), getWorldHeight(), screenWidth, screenHeight);
  int viewportWidth = Math.round(scaled.x);
  int viewportHeight = Math.round(scaled.y);
  // Center.
  setScreenBounds((screenWidth - viewportWidth) / 2, (screenHeight - viewportHeight) / 2, viewportWidth, viewportHeight);
  apply(centerCamera);
}
origin: libgdx/libgdx

@Override
public void update (int screenWidth, int screenHeight, boolean centerCamera) {
  Vector2 scaled = scaling.apply(getWorldWidth(), getWorldHeight(), screenWidth, screenHeight);
  int viewportWidth = Math.round(scaled.x);
  int viewportHeight = Math.round(scaled.y);
  // Center.
  setScreenBounds((screenWidth - viewportWidth) / 2, (screenHeight - viewportHeight) / 2, viewportWidth, viewportHeight);
  apply(centerCamera);
}
origin: libgdx/libgdx

protected void setDisplayMode (int width, int height) {
  Dimension size = new Dimension(Math.round(width / scaleX), Math.round(height / scaleY));
  LwjglFrame.this.getContentPane().setPreferredSize(size);
  LwjglFrame.this.getContentPane().invalidate();
  LwjglFrame.this.pack();
  LwjglFrame.this.setLocationRelativeTo(null);
  updateSize(width, height);
}
origin: libgdx/libgdx

protected void setDisplayMode (int width, int height) {
  Dimension size = new Dimension(Math.round(width / scaleX), Math.round(height / scaleY));
  LwjglFrame.this.getContentPane().setPreferredSize(size);
  LwjglFrame.this.getContentPane().invalidate();
  LwjglFrame.this.pack();
  LwjglFrame.this.setLocationRelativeTo(null);
  updateSize(width, height);
}
origin: libgdx/libgdx

/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)}
 * action. */
public Dialog show (Stage stage) {
  show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
  setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
  return this;
}
origin: libgdx/libgdx

/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)}
 * action. */
public Dialog show (Stage stage) {
  show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
  setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
  return this;
}
origin: libgdx/libgdx

/** Kindly borrowed from PlayN. **/
protected int getRelativeY (NativeEvent e, CanvasElement target) {
  float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling
  return Math.round(yScaleRatio
    * (e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop()));
}
origin: libgdx/libgdx

/** Kindly borrowed from PlayN. **/
protected int getRelativeX (NativeEvent e, CanvasElement target) {
  float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling
  return Math.round(xScaleRatio
    * (e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft()));
}
origin: libgdx/libgdx

/** Kindly borrowed from PlayN. **/
protected int getRelativeX (NativeEvent e, CanvasElement target) {
  float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling
  return Math.round(xScaleRatio
    * (e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft()));
}
origin: libgdx/libgdx

/** Kindly borrowed from PlayN. **/
protected int getRelativeY (NativeEvent e, CanvasElement target) {
  float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling
  return Math.round(yScaleRatio
    * (e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop()));
}
java.langMathround

Javadoc

Returns the result of rounding the argument to an integer. The result is equivalent to (long) Math.floor(d+0.5).

Special cases:

  • round(+0.0) = +0.0
  • round(-0.0) = +0.0
  • round((anything > Long.MAX_VALUE) = Long.MAX_VALUE
  • round((anything < Long.MIN_VALUE) = Long.MIN_VALUE
  • round(+infinity) = Long.MAX_VALUE
  • round(-infinity) = Long.MIN_VALUE
  • round(NaN) = +0.0

Popular methods of Math

  • min
    Returns the smaller of two long values. That is, the result is the argument closer to the value of L
  • max
    Returns the greater of two long values. That is, the result is the argument closer to the value of L
  • abs
    Returns the absolute value of a long value. If the argument is not negative, the argument is returne
  • pow
    Returns the value of the first argument raised to the power of the second argument. Special cases: *
  • sqrt
    Returns the correctly rounded positive square root of a double value. Special cases: * If the argume
  • ceil
    Returns the smallest (closest to negative infinity) double value that is greater than or equal to th
  • floor
    Returns the largest (closest to positive infinity) double value that is less than or equal to the ar
  • random
    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returne
  • sin
    Returns the trigonometric sine of an angle. Special cases: * If the argument is NaN or an infinit
  • cos
    Returns the trigonometric cosine of an angle. Special cases: * If the argument is NaN or an infin
  • log
    Returns the natural logarithm (base e) of a doublevalue. Special cases: * If the argument is NaN
  • exp
    Returns Euler's number e raised to the power of a double value. Special cases: * If the argument
  • log,
  • exp,
  • toRadians,
  • atan2,
  • log10,
  • acos,
  • tan,
  • toDegrees,
  • atan

Popular in Java

  • Reactive rest calls using spring rest template
  • getExternalFilesDir (Context)
  • getSharedPreferences (Context)
  • onCreateOptionsMenu (Activity)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Menu (java.awt)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • String (java.lang)
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Path (java.nio.file)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now