List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("1234"); // assign a larger value to bg2 BigDecimal bg2 = new BigDecimal("123456789098765"); // assign the int value of bg1 and bg2 to i1,i2 respectively int i1 = bg1.intValue(); int i2 = bg2.intValue(); System.out.println(i1);/*from w w w . j a v a 2 s . c om*/ System.out.println(i2); }
From source file:Main.java
public static int convertsToInt(double v) { BigDecimal b = new BigDecimal(v); return b.intValue(); }
From source file:Main.java
public static int getIntHalfUp(float f) { BigDecimal bd = new BigDecimal(f).setScale(BigDecimal.ROUND_HALF_UP); return bd.intValue(); }
From source file:Main.java
public static int getRounding(float f) { BigDecimal a = new BigDecimal(f).setScale(0, BigDecimal.ROUND_HALF_UP); return a.intValue(); }
From source file:Main.java
public static Integer processCurreny(String value) { BigDecimal bd = new BigDecimal(value); bd.setScale(2, BigDecimal.ROUND_HALF_UP); bd = bd.multiply(new BigDecimal(100)); return bd.intValue(); }
From source file:Main.java
/** * Formats decimal number for specified locale * * @param v Value to format/*from w w w . java 2 s.co m*/ * @param locale Locale * @return Formatted string */ public static String formatBigDecimal(BigDecimal v, Locale locale) { NumberFormat numberFormat = NumberFormat.getInstance(locale); int scale = 2; if (v.intValue() >= 100) { scale = 1; } return numberFormat.format(v.setScale(scale, RoundingMode.UP)); }
From source file:com.itellity.comp.type.finance.MonetaryAmountMH.java
/** * Converts a BigDecimal and a Currency to a MonetaryAmount * * @param entity//from w ww. j ava2 s . c o m * @param amount * @param currency * * @return */ public static MonetaryAmount parseValue(Entity entity, BigDecimal amount, Currency currency) { MonetaryAmount money = null; if ((amount == null || amount.intValue() == 0) && ((currency == null) || currency.isUndefined())) { money = MonetaryAmount.UNDEFINED; } else { try { money = new MonetaryAmount(amount == null ? BigDecimal.ZERO : amount, currency); } catch (Exception e) { LOG.error(e.getMessage(), e); money = MonetaryAmount.UNDEFINED; } } return money; }
From source file:org.apache.pdfbox.rendering.TilingPaint.java
/** * Returns the closest integer which is larger than the given number. * Uses BigDecimal to avoid floating point error which would cause gaps in the tiling. */// w w w. ja v a 2 s.c o m private static int ceiling(double num) { BigDecimal decimal = new BigDecimal(num); decimal = decimal.setScale(5, RoundingMode.CEILING); // 5 decimal places of accuracy return decimal.intValue(); }
From source file:org.openlmis.migration.tool.openlmis.requisition.domain.LineItemFieldsCalculator.java
/** * Calculates Adjusted Consumption (N) value and returns it. * The formula is N = RoundUp(C * ((M * 30) / ((M * 30) - X))) * C = Total Consumed Quantity//w w w . j a va 2s . c o m * M = Months in the previous period * N = Adjusted Consumption * X = Total Stockout Days * If non-stockout days is zero the formula is N = C */ public static int calculateAdjustedConsumption(RequisitionLineItem lineItem, int monthsInThePeriod) { int consumedQuantity = zeroIfNull(lineItem.getTotalConsumedQuantity()); if (consumedQuantity == 0) { return 0; } int totalDays = 30 * monthsInThePeriod; int stockoutDays = zeroIfNull(lineItem.getTotalStockoutDays()); int nonStockoutDays = totalDays - stockoutDays; if (nonStockoutDays == 0) { return consumedQuantity; } BigDecimal divide = new BigDecimal(totalDays).divide(new BigDecimal(nonStockoutDays), 1000, BigDecimal.ROUND_HALF_UP); // in OpenLMIS Core is RoundingMode.CEILING BigDecimal adjustedConsumption = new BigDecimal(consumedQuantity).multiply(divide).setScale(0, RoundingMode.HALF_UP); return adjustedConsumption.intValue(); }
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static Integer safeInteger(final BigDecimal number) { Integer result = null;/*from w ww . j a v a 2s . com*/ if (number != null) { result = number.intValue(); } return result; }