List of usage examples for java.lang Math round
public static long round(double a)
From source file:Main.java
/** * Convert HSL values to a RGB Color./*from w ww. ja v a 2 s . c o m*/ * * @param h Hue is specified as degrees in the range 0 - 360. * @param s Saturation is specified as a percentage in the range 1 - 100. * @param l Lumanance is specified as a percentage in the range 1 - 100. * @paran alpha the alpha value between 0 - 1 * adapted from https://svn.codehaus.org/griffon/builders/gfxbuilder/tags/GFXBUILDER_0.2/ * gfxbuilder-core/src/main/com/camick/awt/HSLColor.java */ public static int[] HSLtoRGB(float h, float s, float l, float alpha) { if (s < 0.0f || s > 100.0f) { String message = "Color parameter outside of expected range - Saturation"; throw new IllegalArgumentException(message); } if (l < 0.0f || l > 100.0f) { String message = "Color parameter outside of expected range - Luminance"; throw new IllegalArgumentException(message); } if (alpha < 0.0f || alpha > 1.0f) { String message = "Color parameter outside of expected range - Alpha"; throw new IllegalArgumentException(message); } // Formula needs all values between 0 - 1. h = h % 360.0f; h /= 360f; s /= 100f; l /= 100f; float q = 0; if (l < 0.5) q = l * (1 + s); else q = (l + s) - (s * l); float p = 2 * l - q; int r = Math.round(Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)) * 256)); int g = Math.round(Math.max(0, HueToRGB(p, q, h) * 256)); int b = Math.round(Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)) * 256)); return new int[] { r, g, b }; }
From source file:Main.java
/** * Convert HSL values to a RGB Color.//from w w w .j av a 2s . c o m * * @param h Hue is specified as degrees in the range 0 - 360. * @param s Saturation is specified as a percentage in the range 1 - 100. * @param l Lumanance is specified as a percentage in the range 1 - 100. * @paran alpha the alpha value between 0 - 1 * adapted from https://svn.codehaus.org/griffon/builders/gfxbuilder/tags/GFXBUILDER_0.2/ * gfxbuilder-core/src/main/com/camick/awt/HSLColor.java */ public static int[] HSLtoRGB(float h, float s, float l, float alpha) { if (s < 0.0f || s > 100.0f) { String message = "Color parameter outside of expected range - Saturation"; throw new IllegalArgumentException(message); } if (l < 0.0f || l > 100.0f) { String message = "Color parameter outside of expected range - Luminance"; throw new IllegalArgumentException(message); } if (alpha < 0.0f || alpha > 1.0f) { String message = "Color parameter outside of expected range - Alpha"; throw new IllegalArgumentException(message); } // Formula needs all values between 0 - 1. h = h % 360.0f; h /= 360f; s /= 100f; l /= 100f; float q = 0; if (l < 0.5) q = l * (1 + s); else q = (l + s) - (s * l); float p = 2 * l - q; int r = Math.round(Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)) * 256)); int g = Math.round(Math.max(0, HueToRGB(p, q, h) * 256)); int b = Math.round(Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)) * 256)); int[] array = { r, g, b }; return array; }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.excel.ExcelUtility.java
public static int getInt(HSSFSheet sheet, int row, short col) { HSSFRow hssfRow = getRow(sheet, row); if (hssfRow == null) { return 0; }/*from w w w . j ava 2s.c o m*/ HSSFCell cell = getRow(sheet, row).getCell(col); if (isNull(cell)) { return 0; } return (int) Math.round(cell.getNumericCellValue()); }
From source file:gob.dp.simco.comun.FunctionUtil.java
public static final double redondear(double numero, int decimales) { return Math.round(numero * Math.pow(10, decimales)) / Math.pow(10, decimales); }
From source file:net.eusashead.hateoas.response.impl.CustomerRepository.java
public Page<Customer> listCustomers(Pageable page) { List<Customer> orders = new ArrayList<Customer>(); for (int i = 0; i < page.getPageSize(); i++) { orders.add(new Customer(i, BigDecimal.valueOf(Math.random() * 100), new Date(Math.round(123456789l * Math.random())))); }/*from w w w. j a va2 s . c om*/ return new PageImpl<Customer>(orders, page, 95); }
From source file:com.apress.prospringintegration.corespring.aop.PurchaseOrderDiscountProcessorImpl.java
public Receipt processDiscountOrder(PurchaseOrder order, DiscountStrategy discountStrategy) throws Exception { order.setProcessedTime(Calendar.getInstance().getTime()); float cost = order.getItemCost(); float discountAmt = cost * discountStrategy.discountRate; order.setDiscountAmount(discountAmt); Receipt receipt = new Receipt(); receipt.setPurchaseAmt(cost);//from w w w . ja v a 2 s . c o m receipt.setDiscountedAmount(discountAmt); receipt.setAuthcode(Math.round(Math.random() * 2000000)); return receipt; }
From source file:Number.java
/** * Round a float to the specified number of decimal places. * // w w w . j a va2 s . com * @param value * The value to round. * @param places * The number of decimal points. * @return The rounded value as a float. */ public static float Round(float value, int places) { float p = (float) Math.pow(10, places); value = value * p; float tmp = Math.round(value); return (float) tmp / p; }
From source file:gui.Histograma.java
private static IntervalXYDataset criarDataset() { //guarda os dados do histograma HistogramDataset dados = new HistogramDataset(); int classes;//ww w .j ava2s .com double valores[] = new double[amostra.size()]; //Definindo quantidade de classes if (amostra.size() <= 25) { classes = 5; } else { classes = (int) Math.round(Math.sqrt(amostra.size())); } //Criando vetor com valores da amostra for (int i = 0; i < amostra.size(); i++) { valores[i] = amostra.get(i); } //Adicionando os dataset para o histograma dados.addSeries("Frequncia das Amostras", valores, classes, min, max); return dados; }
From source file:Main.java
@SuppressLint("NewApi") public static Bitmap createVideoThumbnail(String filePath, int kind) { Bitmap bitmap = null;/* ww w.j a v a 2 s . c om*/ if (Build.VERSION.SDK_INT < 10) { // This peace of code is for compatibility with android 8 and 9. return android.media.ThumbnailUtils.createVideoThumbnail(filePath, kind); } // MediaMetadataRetriever is not available for Android version less than 10 // but we need to use it in order to get first frame of the video for thumbnail. MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(filePath); bitmap = retriever.getFrameAtTime(0); } catch (IllegalArgumentException ex) { // Assume this is a corrupt video file } catch (RuntimeException ex) { // Assume this is a corrupt video file. } finally { try { retriever.release(); } catch (RuntimeException ex) { // Ignore failures while cleaning up. Log.w("ThumbnailUtils", "MediaMetadataRetriever failed with exception: " + ex); } } if (bitmap == null) return null; if (kind == Images.Thumbnails.MINI_KIND) { // Scale down the bitmap if it's too large. int width = bitmap.getWidth(); int height = bitmap.getHeight(); int max = Math.max(width, height); if (max > 512) { float scale = 512f / max; int w = Math.round(scale * width); int h = Math.round(scale * height); bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true); } } else if (kind == Images.Thumbnails.MICRO_KIND) { bitmap = android.media.ThumbnailUtils.extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL, TARGET_SIZE_MICRO_THUMBNAIL, OPTIONS_RECYCLE_INPUT); } return bitmap; }
From source file:geogebra.common.kernel.statistics.AlgoPascal.java
@Override public final void compute() { if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined() && input[3].isDefined()) { int param = (int) Math.round(a.getDouble()); double param2 = b.getDouble(); double val = c.getDouble(); try {//from w w w . jav a 2 s . c o m PascalDistribution dist = getPascalDistribution(param, param2); if (isCumulative.getBoolean()) num.setValue(dist.cumulativeProbability(val)); // P(X <= // val) else num.setValue(dist.probability(val)); // P(X = val) } catch (Exception e) { num.setUndefined(); } } else num.setUndefined(); }