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 double toPrecision(double v, int precision) {
    double factor = Math.pow(10, precision);
    return Math.round(v * factor) / factor;
}

From source file:Main.java

public static int getInt(String string, int fallBack) {
    int i;/*www  .j ava2 s  . co  m*/
    try {
        i = (int) Math.round(getDouble(string, fallBack));
    } catch (Exception e) {
        i = fallBack;
    }
    return i;
}

From source file:Main.java

private static int getMiddleValue(int prev, int next, float factor) {
    return Math.round(prev + (next - prev) * factor);
}

From source file:Main.java

private static int getImageSizeFromCoef(float coef, int viewSideSize) {
    return Math.round(viewSideSize * coef);
}

From source file:Main.java

public static double xround(double x, int num) {
    Log.e("---------- ", "" + x);
    return Math.round(x * Math.pow(10, num)) / Math.pow(10, num);
}

From source file:Main.java

public static String conversionDistanse(int aDistanceMeter) {
    return (aDistanceMeter >= 1000) ? Math.round((new BigDecimal(String.valueOf(aDistanceMeter / 1000))
            .setScale(1, BigDecimal.ROUND_HALF_UP).longValue())) + "km" : aDistanceMeter + "m";
}

From source file:Main.java

public static double roundNumber(double rowNumber, int roundingPoint) {
    double base = Math.pow(10D, roundingPoint);
    return Math.round(rowNumber * base) / base;
}

From source file:Main.java

public static int dp2px(Context context, int dp) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()));
}

From source file:Main.java

public static java.util.Date sqlTimestampToDate(Timestamp t) {

    return t != null ? new java.util.Date(Math.round(t.getTime() + t.getNanos() / 1000000D)) : null;
}

From source file:Main.java

public static int getDarkerColor(int color) {
    int alpha = Color.alpha(color);
    int red = Math.round(Color.red(color) * 0.625f);
    int green = Math.round(Color.green(color) * 0.625f);
    int blue = Math.round(Color.blue(color) * 0.625f);
    return Color.argb(alpha, red, green, blue);
}