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 color2LedRed(int color) {
    int red = (color >> RED_SHIFT) & 0xFF;
    int newRed = (int) Math.round(red * (LED_INTENSITY_LEVEL_COUNT - 1) / (double) 0xFF);

    return newRed;
}

From source file:Main.java

public static int convertDpToPx(Context context, int dp) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (metrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/* w w w  . j av  a2s . com*/
}

From source file:Main.java

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

From source file:Main.java

/**
 * /*  www.  jav  a 2s .  c  om*/
 * @param input
 * @return
 */
public static int fourToDegrees(String input) {
    int deg = Integer.parseInt(input);
    float rnd = Math.round((float) deg / (float) DEGREES_PER_SEC) * (float) DEGREES_PER_SEC;
    deg = (int) rnd;
    return deg;
}

From source file:Main.java

public static int color2LedBlue(int color) {
    int blue = (color >> BLUE_SHIFT) & 0xFF;
    int newBlue = (int) Math.round(blue * (LED_INTENSITY_LEVEL_COUNT - 1) / (double) 0xFF);

    return newBlue;
}

From source file:Main.java

public static int convertDpToPixel(Context context, float f) {
    // TODO Auto-generated method stub
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round((float) f * density);
}

From source file:Main.java

public static int dip2Px(Resources res, int dip) {

    DisplayMetrics dm = res.getDisplayMetrics();
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, dm));
}

From source file:Main.java

public static int scaleDpToPixels(double value, Resources res) {
    final float scale = res.getDisplayMetrics().density;
    return (int) Math.round(value * scale);
}

From source file:Main.java

public static int color2LedGreen(int color) {
    int green = (color >> GREEN_SHIFT) & 0xFF;
    int newGreen = (int) Math.round(green * (LED_INTENSITY_LEVEL_COUNT - 1) / (double) 0xFF);

    return newGreen;
}

From source file:Main.java

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

    long factor = (long) Math.pow(10, places);
    value = value * factor;//  w ww  .  j ava  2  s  . com
    long tmp = Math.round(value);
    return (double) tmp / factor;
}