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, float dp) {
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round(dp * density);
}

From source file:Main.java

public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;
    if (height > reqHeight || width > reqWidth) {
        // Calculate ratios of height and width to requested height and
        // width//from  ww  w.  ja v  a2  s  .  c o m
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);
        // Choose the smallest ratio as inSampleSize value, this will
        // guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio > widthRatio ? heightRatio : widthRatio;
    }
    return inSampleSize;
}

From source file:Main.java

public static double GetDistance(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);

    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;//from w ww  .ja  v  a2  s.  c  o m
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double DistanceOfTwoPoints(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;// w ww  .j a  va2 s  .  co m
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static int calculateInSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight) {
    // Raw height and width of image  
    int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (reqWidth <= 0 || reqHeight <= 0)
        return inSampleSize;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = Math.round(height / reqHeight);
        } else {//ww w.ja va2 s  .  c  om
            inSampleSize = Math.round(width / reqWidth);
        }
    }
    return Math.round(height / reqHeight);
}

From source file:Main.java

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;
    if (height > reqHeight || width > reqWidth) {
        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);
        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the requested height and width.
        inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;
    }//w  w  w  .  j a  v  a2  s . co  m
    return inSampleSize;
}

From source file:com.civprod.writerstoolbox.OpenNLP.training.FileSplit.java

public static List<FileSplit> generateFileSplitsKFolds(List<File> inTrainingFiles, int k) {
    int foldSize = (int) Math.round(((double) inTrainingFiles.size()) / ((double) k));
    return generateFileSplitsFoldsOfK(inTrainingFiles, foldSize);
}

From source file:Main.java

public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {

    double Lat1 = rad(latitude1);
    double Lat2 = rad(latitude2);
    double a = Lat1 - Lat2;
    double b = rad(longitude1) - rad(longitude2);
    double s = 2 * Math.asin(Math.sqrt(
            Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;/*from  ww w  . j  a  v a 2s. c o m*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static int daysSince(final long date) {
    final Calendar logDate = Calendar.getInstance();
    logDate.setTimeInMillis(date);//from w  ww .  j  a v  a 2s  . com
    logDate.set(Calendar.SECOND, 0);
    logDate.set(Calendar.MINUTE, 0);
    logDate.set(Calendar.HOUR_OF_DAY, 0);
    final Calendar today = Calendar.getInstance();
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
}

From source file:Main.java

/**
 * Alters the alpha of the given color without multiplying the current value.
 * The current alpha value is replaced by the new one. See {#getNewColorAlpha} to see
 * how to get a new alpha color by multiplying the current value by the new value.
 * @param color the color to alter.// w  w  w  .j av a 2 s .  c o  m
 * @param value the new alpha value.
 * @return the new color.
 */
public static int getNewColorAlphaNoMult(int color, float value) {
    int alpha = Math.round(value);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);
    return Color.argb(alpha, r, g, b);
}