List of usage examples for java.lang Math round
public static long round(double a)
From source file:Main.java
public static double pxToDp(Context context, double px) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); double dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return dp;// www . j ava 2 s. com }
From source file:Main.java
public static double dpToPx(Context context, double dp) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); double px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return px;//from w ww . j av a 2 s. co m }
From source file:Main.java
public static Double round(double value, int precision) { int scale = (int) Math.pow(10, precision); return (double) Math.round(value * scale) / scale; }
From source file:Main.java
private static boolean checkNum(int num) { boolean needsAn = false; // eight, eleven, eighty and eighteen if (num == 11 || num == 18 || num == 8 || (num >= 80 && num < 90)) { needsAn = true;// w w w .java 2s . co m } else if (num > 1000) { num = Math.round(num / 1000); needsAn = checkNum(num); } return needsAn; }
From source file:Main.java
public static double round(double amount) { return (Math.round(amount * 100.0D) / 100.0D); }
From source file:Main.java
public static double round(double value, int places) { if (places < 0) { throw new IllegalArgumentException(); }/*from w w w. ja va2 s.com*/ long factor = (long) Math.pow(10, places); value = value * factor; long tmp = Math.round(value); return (double) tmp / factor; }
From source file:Main.java
public static int dpToPx(Context mContext, int dp) { if (mContext == null) { return 0; }//from w w w . j a v a 2s . c o m DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return px; }
From source file:Main.java
/** * Converts a size value in dp scale into pixel scale. *//*from ww w .j ava2 s . c o m*/ 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 source file:Main.java
/** * Converts a size value in pixel scale into dp scale. *//*from w ww . ja v a 2 s . co m*/ public static int pxToDp(Context context, int px) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return dp; }
From source file:Main.java
public static int scalePow2(int height, int width) { int scale = 1; int size = Math.max(height, width); if (size > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) size) / Math.log(0.5))); }//from ww w. j a v a 2s . c o m return scale; }