System.out.println(new BigDecimal(1.03).subtract(new BigDecimal(0.41))); System.out.println(new BigDecimal("1.03").subtract(new BigDecimal("0.41")));
public static int extractNanosecondDecimal(BigDecimal value, long integer) { // !!! 14-Mar-2016, tatu: Somewhat inefficient; should replace with functionally // equivalent code that just subtracts integral part? (or, measure and show // there's no difference and do nothing... ) return value.subtract(new BigDecimal(integer)).multiply(ONE_BILLION).intValue(); } }
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; }
if (to instanceof BigDecimal) { BigDecimal to1 = (BigDecimal) to; if (self.compareTo(to1) >= 0) { for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) { closure.call(i); throw new GroovyRuntimeException("The argument (" + to + ") to downto() cannot be greater than the value (" + self + ") it's called on."); } else if (to instanceof BigInteger) { BigDecimal to1 = new BigDecimal((BigInteger) to); if (self.compareTo(to1) >= 0) { for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) { closure.call(i); throw new GroovyRuntimeException("The argument (" + to + ") to downto() cannot be greater than the value (" + self + ") it's called on."); } else { BigDecimal to1 = new BigDecimal(to.toString()); if (self.compareTo(to1) >= 0) { for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) { closure.call(i);
final BigInteger toTemp = new BigInteger(to.toString()); final BigInteger toNum = inclusive ? toTemp : toTemp.subtract(BigInteger.ONE); final BigInteger sizeNum = new BigDecimal(toNum.subtract(fromNum)).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE); tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == -1 ? sizeNum.intValue() : Integer.MAX_VALUE; shortcut = true; ((to instanceof BigDecimal || to instanceof BigInteger) && from instanceof Number)) { final BigDecimal fromNum = new BigDecimal(from.toString()); final BigDecimal toTemp = new BigDecimal(to.toString()); final BigDecimal toNum = inclusive ? toTemp : toTemp.subtract(new BigDecimal("1.0")); final BigInteger sizeNum = toNum.subtract(fromNum).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE); tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == -1 ? sizeNum.intValue() : Integer.MAX_VALUE; shortcut = true;
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)); } }
/** * Returns the amount of the <code>currency</code> in this balance that is available to trade. * * @return the amount that is available to trade. */ public BigDecimal getAvailable() { if (available == null) { return total .subtract(frozen) .subtract(loaned) .add(borrowed) .subtract(withdrawing) .subtract(depositing); } else { return available; } }
/** * Canonicalize the current latitude and longitude values such that: * * <pre> * -90 <= latitude <= +90 - 180 < longitude <= +180 * </pre> */ private void canonicalize(DecimalType aLat, DecimalType aLon) { latitude = flat.add(aLat.toBigDecimal()).remainder(circle); longitude = aLon.toBigDecimal(); if (latitude.compareTo(BigDecimal.ZERO) == -1) { latitude.add(circle); } latitude = latitude.subtract(flat); if (latitude.compareTo(right) == 1) { latitude = flat.subtract(latitude); longitude = longitude.add(flat); } else if (latitude.compareTo(right.negate()) == -1) { latitude = flat.negate().subtract(latitude); longitude = longitude.add(flat); } longitude = flat.add(longitude).remainder(circle); if (longitude.compareTo(BigDecimal.ZERO) <= 0) { longitude = longitude.add(circle); } longitude = longitude.subtract(flat); }
RippleTradeServiceRaw.getExpectedTransferFee( transferFeeSource, base.getCounterparty(), base.getCurrency(), base.getValue(), type); final BigDecimal baseValue = base.getValue().abs().subtract(baseTransferFee); counter.getValue(), counterDirection); final BigDecimal counterValue = counter.getValue().abs().subtract(counterTransferFee); if (base.getCurrency().equals("XRP")) { if (type == OrderType.BID) { quantity = baseValue.add(transactionFee); } else { // OrderType.ASK quantity = baseValue.subtract(transactionFee); if (counter.getCurrency().equals("XRP")) { if (type == OrderType.ASK) { counterAmount = counterValue.add(transactionFee); } else { // OrderType.BID counterAmount = counterValue.subtract(transactionFee); final BigDecimal price = counterAmount.divide(quantity, scale, RoundingMode.HALF_UP);
cartPromotionItem.setReduceAmount(originalPrice.subtract(skuStock.getPromotionPrice())); cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock()); cartPromotionItem.setIntegration(promotionProduct.getGiftPoint()); BigDecimal reduceAmount = originalPrice.subtract(ladder.getDiscount().multiply(originalPrice)); cartPromotionItem.setReduceAmount(reduceAmount); cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock()); BigDecimal reduceAmount = originalPrice.divide(totalAmount,RoundingMode.HALF_EVEN).multiply(fullReduction.getReducePrice()); cartPromotionItem.setReduceAmount(reduceAmount); cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
/** * The raw transfer rate is represented as an integer, the amount that must be sent in order for 1 * billion units to arrive. For example, a 20% transfer fee is represented as the value 120000000. * The value cannot be less than 1000000000. Less than that would indicate giving away money for * sending transactions, which is exploitable. You can specify 0 as a shortcut for 1000000000, * meaning no fee. * * @return percentage transfer rate charge */ public BigDecimal getTransferFeeRate() { if (transferRate == 0) { return BigDecimal.ZERO; } else { return BigDecimal.valueOf(transferRate) .divide(TRANSFER_RATE_DENOMINATOR) .subtract(BigDecimal.ONE); } }
/** * Returns a {@code BigDecimal} array which contains the integral part of * {@code this / divisor} at index 0 and the remainder {@code this % * divisor} at index 1. The quotient is rounded down towards zero to the * next integer. * * @param divisor * value by which {@code this} is divided. * @return {@code [this.divideToIntegralValue(divisor), * this.remainder(divisor)]}. * @throws NullPointerException * if {@code divisor == null}. * @throws ArithmeticException * if {@code divisor == 0}. * @see #divideToIntegralValue * @see #remainder */ public BigDecimal[] divideAndRemainder(BigDecimal divisor) { BigDecimal quotAndRem[] = new BigDecimal[2]; quotAndRem[0] = this.divideToIntegralValue(divisor); quotAndRem[1] = this.subtract( quotAndRem[0].multiply(divisor) ); return quotAndRem; }
private void sendPaymentsFor(Repository repository, List<Commit> commits, BigDecimal balance, BigDecimal exchangeRate) { for (Commit commit : commits) { try { BigDecimal payout = balance.multiply(payoutRate); if (isViablePaymentAmount(payout)) { coinbaseClient.sendPayment(commit.getAuthor(), payout, commit.getUrl()); } balance = balance.subtract(payout); githubClient.addCommitComment(repository, commit, getCommitCommentStringForPayment(payout, exchangeRate)); } catch (TransferFailedException e) { logger.warn("Transfer failed", e); } } }
private BigDecimal calcTotalAmountByProductId(List<CartPromotionItem> cartItemList,List<Long> productIds) { BigDecimal total = new BigDecimal("0"); for (CartPromotionItem item : cartItemList) { if(productIds.contains(item.getProductId())){ BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); } } return total; }
public static int extractNanosecondDecimal(BigDecimal value, long integer) { // !!! 14-Mar-2016, tatu: Somewhat inefficient; should replace with functionally // equivalent code that just subtracts integral part? (or, measure and show // there's no difference and do nothing... ) return value.subtract(new BigDecimal(integer)).multiply(ONE_BILLION).intValue(); } }
/** * Creates JD from <code>BigDecimal</code>. */ public JulianDateStamp(BigDecimal bd) { double d = bd.doubleValue(); integer = (int) d; bd = bd.subtract(new BigDecimal(integer)); fraction = bd.doubleValue(); }
final BigDecimal one = BigDecimal.valueOf(10, 1); // That's what you get for "1.0". final BigDecimal to1 = (BigDecimal) to; final BigDecimal selfD = new BigDecimal(self); if (selfD.compareTo(to1) >= 0) { for (BigDecimal i = selfD; i.compareTo(to1) >= 0; i = i.subtract(one)) { closure.call(i.toBigInteger());