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 dpToPx(Context context, int dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;//from ww  w . j  a v  a 2 s . co m
}

From source file:Main.java

public static Bitmap binarize(Bitmap bmp) {
    int threshold = Math.round(getOtsuThreshold(bmp));
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int[] pixels = new int[width * height];
    bmp.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int i = 0; i < width * height; i++) {
        int p = 0;
        if (Color.red(pixels[i]) > threshold)
            p = 255;/*www  . ja  v  a  2 s .co m*/
        pixels[i] = Color.rgb(p, p, p);
    }

    return Bitmap.createBitmap(pixels, width, height, bmp.getConfig());
}

From source file:Main.java

/**
 *
 * @param d eot in hours/* ww w  . j av  a 2 s  .c om*/
 * @return formatted string
 */
public final static String eotToString(double d) {
    int m = (int) Math.floor(Math.abs(d) * 60d);
    int s = (int) Math.round((3600d * Math.abs(d)) - (m * 60d));
    return ((d > 0 ? "+" : "-") + Integer.toString(m) + "m" + Integer.toString(s) + "s");
}

From source file:Main.java

static int dp2px(int dp) {
    return Math.round(dp * DENSITY);
}

From source file:Main.java

public static void waitSeconds(double seconds) {
    waitMillis(Math.round(seconds * 1000));
}

From source file:Main.java

public static int dpToPx(Context cx, int dp) {
    DisplayMetrics displayMetrics = cx.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*from  w  w  w.  j  av  a 2 s.  c  o  m*/
}

From source file:Main.java

public static float truncate(float f, int decimalPlaces) {
    float decimalShift = (float) Math.pow(10, decimalPlaces);
    return Math.round(f * decimalShift) / decimalShift;
}

From source file:Main.java

static int dpToPx(Context context, float dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return Math.round(dp * scale);
}

From source file:Main.java

public static int convertPxToDp(Context context, int px) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    int dp = Math.round(px / (metrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return dp;/*from   w ww  .  j  av a2 s  . c  om*/
}

From source file:Main.java

public static int dpToPx(Activity context, int dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;//from w ww  .  ja va2s.  c om
}