本文整理了Java中java.math.BigDecimal.subtract()
方法的一些代码示例,展示了BigDecimal.subtract()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.subtract()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:subtract
[英]Returns a new BigDecimal whose value is this - subtrahend. The scale of the result is the maximum of the scales of the two arguments.
[中]返回一个新的BigDecimal,其值为this-subtrahand。结果的范围是两个参数范围的最大值。
代码示例来源:origin: stackoverflow.com
System.out.println(new BigDecimal(1.03).subtract(new BigDecimal(0.41)));
System.out.println(new BigDecimal("1.03").subtract(new BigDecimal("0.41")));
代码示例来源:origin: prestodb/presto
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();
}
}
代码示例来源:origin: org.assertj/assertj-core
@Override
protected boolean isGreaterThan(BigDecimal value, BigDecimal other) {
return value.subtract(other).compareTo(ZERO) > 0;
}
代码示例来源:origin: macrozheng/mall
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;
}
代码示例来源:origin: org.codehaus.groovy/groovy
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);
代码示例来源:origin: org.codehaus.groovy/groovy
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;
代码示例来源:origin: apache/hive
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));
}
}
代码示例来源:origin: knowm/XChange
/**
* 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;
}
}
代码示例来源:origin: openhab/openhab1-addons
/**
* 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);
}
代码示例来源:origin: knowm/XChange
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);
代码示例来源:origin: macrozheng/mall
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());
代码示例来源:origin: knowm/XChange
/**
* 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);
}
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: signalapp/BitHub
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);
}
}
}
代码示例来源:origin: macrozheng/mall
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;
}
代码示例来源:origin: bootique/bootique
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();
}
}
代码示例来源:origin: redisson/redisson
/**
* 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();
}
代码示例来源:origin: org.codehaus.groovy/groovy
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());
代码示例来源:origin: knowm/XChange
/**
* Returns the total amount of the <code>currency</code> in this balance.
*
* @return the total amount.
*/
public BigDecimal getTotal() {
if (total == null) {
return available.add(frozen).subtract(borrowed).add(loaned).add(withdrawing).add(depositing);
} else {
return total;
}
}
代码示例来源:origin: joel-costigliola/assertj-core
@Override
protected boolean isGreaterThan(BigDecimal value, BigDecimal other) {
return value.subtract(other).compareTo(ZERO) > 0;
}
内容来源于网络,如有侵权,请联系作者删除!