/** * Returns <code>BigDecimal</code> value of JD. */ @SuppressWarnings({"UnpredictableBigDecimalConstructorCall"}) public BigDecimal toBigDecimal() { BigDecimal bd = new BigDecimal(integer); return bd.add(new BigDecimal(fraction)); }
BigDecimal _0_1 = new BigDecimal(0.1); BigDecimal x = _0_1; for(int i = 1; i <= 10; i ++) { System.out.println(i+" x 0.1 is "+x+", as double "+x.doubleValue()); x = x.add(_0_1); }
private BigDecimal calcTotalAmount(List<CartPromotionItem> cartItemList) { BigDecimal total = new BigDecimal("0"); for (CartPromotionItem item : cartItemList) { BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); } return total; }
public static void main(String[] args) throws Exception { BigDecimal totalDataSize = new BigDecimal("0.0"); BigDecimal max = new BigDecimal("0.0"); BigDecimal min = new BigDecimal("0.0"); BigDecimal avg = new BigDecimal("0.0"); long maxQueueSize = 0L; InputStream gzipStream = new GZIPInputStream(fileStream); System.out.println("Using flow=" + input); ? convertSizeToByteValue(maxDataSize) : new BigDecimal("0.0"); numberOfConnections++; avg = avg.add(byteValue); String dataQueueSize = maxWorkQueueSize.getElementsByTagName("maxWorkQueueSize").item(0) .getTextContent(); min = byteValue; totalDataSize = totalDataSize.add(byteValue);
tickLabels.add(numberFormatter.format(BigDecimal.valueOf(maxValue).doubleValue())); tickLocations.add(workingSpace / 2.0); return; BigDecimal gridStepBigDecimal = new BigDecimal(gridStep, MathContext.DECIMAL64); tickLabels.add(numberFormatter.format(BigDecimal.valueOf((maxValue + minValue) / 2.0))); tickLocations.add(workingSpace / 2.0); return; } else if (firstPositionAsDouble == Double.NEGATIVE_INFINITY) { firstPosition = BigDecimal.valueOf(-1 * Double.MAX_VALUE); } else { try { } catch (java.lang.NumberFormatException e) { System.out.println( "Some debug stuff. This happens once in a blue moon, and I don't know why."); System.out.println("scale: " + scale); System.out.println("exponent: " + exponent); System.out.println("gridStep: " + gridStep); System.out.println("cleanedGridStep: " + cleanedGridStep); value.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; value = value.add(cleanedGridStep)) {
public class Payment { BigDecimal itemCost = BigDecimal.ZERO; BigDecimal totalCost = BigDecimal.ZERO; public BigDecimal calculateCost(int itemQuantity, BigDecimal itemPrice) { itemCost = itemPrice.multiply(new BigDecimal(itemQuantity)); totalCost = totalCost.add(itemCost); return totalCost; } }
public BigDecimal getAveragePrice() { return low.add(high).divide(new BigDecimal("2")); }
@Test(groups = "fast") public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException { final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1); final LocalDate targetDate = invoiceUtil.buildDate(2012, 1, 17); final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27); BigDecimal expectedValue; expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD); expectedValue = expectedValue.add(ONE); expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD)); expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD); testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue); }
@VisibleForTesting public static BigDecimal average(LongDecimalWithOverflowAndLongState state, DecimalType type) { BigDecimal sum = new BigDecimal(Decimals.decodeUnscaledValue(state.getLongDecimal()), type.getScale()); BigDecimal count = BigDecimal.valueOf(state.getLong()); if (state.getOverflow() != 0) { BigInteger overflowMultiplier = TWO.shiftLeft(UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 2); BigInteger overflow = overflowMultiplier.multiply(BigInteger.valueOf(state.getOverflow())); sum = sum.add(new BigDecimal(overflow)); } return sum.divide(count, type.getScale(), ROUND_HALF_UP); }
public static Number add(BigInteger first, double second) { return new BigDecimal(first).add(BigDecimal.valueOf(second)); }
public BigDecimal randHiveBigDecimalNear(Random r, BigDecimal bigDecimal) { int scale = bigDecimal.scale(); int delta = r.nextInt(10); if (r.nextBoolean()) { return bigDecimal.add(new BigDecimal(BigInteger.valueOf(delta), scale)); } else { return bigDecimal.subtract(new BigDecimal(BigInteger.valueOf(delta), scale)); } }
@Override public BigDecimal getBigNumber( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } BigDecimal nanos = BigDecimal.valueOf( timestamp.getTime() ).multiply( BigDecimal.valueOf( 1000000000L ) ).add( BigDecimal.valueOf( timestamp.getNanos() ) ); return nanos; }
@Override public SqlDecimal getExpectedValue(int start, int length) { if (length == 0) { return null; } BigDecimal avg = BigDecimal.ZERO; for (int i = start; i < start + length; i++) { avg = avg.add(getBigDecimalForCounter(i)); } avg = avg.divide(BigDecimal.valueOf(length), ROUND_HALF_UP); return new SqlDecimal(avg.unscaledValue(), avg.precision(), avg.scale()); }
BigDecimal test = new BigDecimal(0); System.out.println(test); test = test.add(new BigDecimal(30)); System.out.println(test); test = test.add(new BigDecimal(45)); System.out.println(test);
private BigDecimal calcTotalAmountByproductCategoryId(List<CartPromotionItem> cartItemList,List<Long> productCategoryIds) { BigDecimal total = new BigDecimal("0"); for (CartPromotionItem item : cartItemList) { if(productCategoryIds.contains(item.getProductCategoryId())){ BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); } } return total; }