List of usage examples for java.lang Math round
public static long round(double a)
From source file:Main.java
public static String roundOffToTwoDecimal(String valueStr) { double valueDouble = new Double(valueStr).doubleValue(); double roundOff = (double) Math.round(valueDouble * 100) / 100; return new Double(roundOff).toString(); }
From source file:Main.java
/** * Get scale for image of size and max height/width * /*w w w.j a v a 2 s . c om*/ * @param size * @param width * @param height * @return scale */ public static int getScale(Point size, int width, int height) { if (size.x > width || size.y > height) return Math.max(Math.round((float) size.y / (float) height), Math.round((float) size.x / (float) width)); else return 1; }
From source file:Main.java
/** * Function to convert the given size in dp. * @param mContext context of the activity. * @param iValue value the needed to be changed. * @return value in dp/*from w ww . j av a2s . c om*/ */ public static int getSizeInDp(Context mContext, int iValue) { return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iValue, mContext.getResources().getDisplayMetrics())); }
From source file:Main.java
public static int px2dp(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return Math.round(pxValue / scale); }
From source file:Main.java
public static int dp2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return Math.round(dpValue * scale); }
From source file:Main.java
public static void multiply(final long[] pArray, final double pFactor) { for (int i = 0; i < pArray.length; i++) { pArray[i] = Math.round(pArray[i] * pFactor); }// w ww .j a va 2 s.c o m }
From source file:Main.java
public static int caculateInSampleSize(Options options, int reqWidth, int reqHeight) { int width = options.outWidth; int height = options.outHeight; int inSampleSize = 1; if (width > reqWidth || height > reqHeight) { int widthRadio = Math.round(width * 1.0f / reqWidth); int heightRadio = Math.round(height * 1.0f / reqHeight); inSampleSize = Math.max(widthRadio, heightRadio); }// w w w.j a v a 2s. c om return inSampleSize; }
From source file:Main.java
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { int width = options.outWidth; int height = options.outHeight; int inSampleSize = 1; if (width > reqWidth || height > reqHeight) { int widthRadio = Math.round(width * 1.0f / reqWidth); int heightRadio = Math.round(height * 1.0f / reqHeight); inSampleSize = Math.max(widthRadio, heightRadio); }/*from w w w .j a v a 2 s . com*/ return inSampleSize; }
From source file:Main.java
public static int dpToPixel(int dp) { return Math.round(dpToPixel((float) dp)); }
From source file:Main.java
private static int getIdealSizeFromResourceInDp(Context context, int resource) { float sizeInPx = context.getResources().getDimension(resource); float density = context.getResources().getDisplayMetrics().density; return Math.round(sizeInPx / density); }