Example usage for java.lang Math round

List of usage examples for java.lang Math round

Introduction

In this page you can find the example usage for java.lang Math round.

Prototype

public static long round(double a) 

Source Link

Document

Returns the closest long to the argument, with ties rounding to positive infinity.

Usage

From source file:Main.java

public static int argb(int color, float a) {
    int alpha = Math.round((a * 255));
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);

    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

/**
 * Converts speed from m/s to km/h//  w  w w . j  av a2 s.c o  m
 * @param speedMs
 * @return
 */
public static int ms2Kmh(float speedMs) {
    return (int) Math.round(speedMs * 3.6);
}

From source file:Main.java

public static int getDiffDayByTimeStamp(long startTimeStamp, long endTimeStamp) {
    return Math.round((endTimeStamp - startTimeStamp) * 1.0f / ONE_DAY_TIME);
}

From source file:Main.java

public static int meterToPixel(float meter) {
    // 1 meter = 39.37 inches, 1 inch = 160 dp.
    return Math.round(dpToPixel(meter * 39.37f * 160));
}

From source file:Main.java

public static String formatDouble(double d) {
    DecimalFormat formatter = new DecimalFormat("#,###.##");
    d = Math.round(d);
    return formatter.format(d);
}

From source file:Main.java

/**
 * /*from w w  w.j  a  va 2s.  c  om*/
 * @param r
 * @param g
 * @param b
 * @return
 */
public static int rgb2gray(int r, int g, int b) {
    return (int) Math.round(0.299 * r + 0.587 * g + 0.114 * b);
}

From source file:Main.java

public static int getColor(int baseColor, float alphaPercent) {
    int alpha = Math.round(Color.alpha(baseColor) * alphaPercent);

    return (baseColor & 0x00FFFFFF) | (alpha << 24);
}

From source file:Main.java

/**
 * Fix number to 2 decimal places/*  ww w  . jav  a  2 s . c o m*/
 * @param dbl
 * @return
 */
public static float fixNumber(double dbl) {
    int ix = (int) (Math.round(dbl * 100.0));
    return ix / 100.0f;
}

From source file:Main.java

static int dpToPx(float dp, float ppi, DisplayMetrics displayMetrics) {
    dp /= displayMetrics.density;/*from  w ww.  jav a2 s .  co m*/
    int px = Math.round(dp * (ppi / DisplayMetrics.DENSITY_DEFAULT));
    return px;
}

From source file:Main.java

public static int getRndNum(int min, int max) {
    return (int) Math.round((max - min) * Math.random() + min);
}