本文整理汇总了Java中java.math.BigDecimal.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.subtract方法的具体用法?Java BigDecimal.subtract怎么用?Java BigDecimal.subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.subtract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testItem_0024
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0024()
{
BigDecimal alpha = new BigDecimal("1000").setScale(0);
BigDecimal beta = new BigDecimal("0.70").setScale(2);
BigDecimal gamma = alpha.subtract(beta);
gamma.setScale(2);
Assert.assertEquals("999.30", gamma.toString());
}
示例2: splitRedPackets
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public List<BigDecimal> splitRedPackets(BigDecimal totalMoney, int totalPeople) {
List<BigDecimal> result = new ArrayList<>();
// 每个红包平均分到的金额
BigDecimal averageMoney = totalMoney.divide(new BigDecimal(totalPeople), RedPacketsConfig.MONEY_SCALE, RoundingMode.DOWN);
// 最后一个红包的金额
BigDecimal lastMoney = totalMoney.subtract(averageMoney.multiply(new BigDecimal(totalPeople - 1)));
for (int i = 0; i < totalPeople - 1; i++) {
result.add(averageMoney);
}
result.add(lastMoney);
Collections.shuffle(result);
return result;
}
示例3: calculateInterest
import java.math.BigDecimal; //导入方法依赖的package包/类
/** Calculates interest for the loan over it's next n-many periods */
public BigDecimal calculateInterest(int n){
if(n <= 0) return BigDecimal.ZERO; //if it's zero or a negative number, just return zero
BigDecimal tempAmount = new BigDecimal( amount.toString() );
while(n > 0){ //just keep accruing interest using the same formula as calculateInterest()
tempAmount = interestRate.divide(new BigDecimal(100), 5, RoundingMode.CEILING) //convert from percent to decimal
.multiply(period)
.divide(new BigDecimal("365.25"), 11, RoundingMode.CEILING)
.add(BigDecimal.ONE)
.multiply(tempAmount)
.divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
n--;
}
tempAmount = tempAmount.subtract(amount); //now take the difference
return tempAmount;
}
示例4: create
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Create a graph
* @param goalInKg the goal set
* @param measurements the measurement data
* @return a chart
*/
public Chart create(BigDecimal goalInKg, Iterable<WeightMeasurement> measurements) {
BigDecimal minValue = goalInKg;
BigDecimal maxValue = goalInKg;
List<List<Object>> dataPoints = new ArrayList<>();
for (WeightMeasurement wm : measurements) {
if (minValue == null) {
minValue = wm.getWeightInKg();
} else {
minValue = minValue.min(wm.getWeightInKg());
}
if (maxValue == null) {
maxValue = wm.getWeightInKg();
} else {
maxValue = maxValue.max(wm.getWeightInKg());
}
dataPoints.add(Lists.newArrayList(wm.getDateTime().toInstant(ZoneOffset.UTC).toEpochMilli(),wm.getWeightInKg()));
}
if (minValue != null) {
minValue = minValue.subtract(BigDecimal.valueOf(1));
}
if (maxValue != null) {
maxValue = maxValue.add(BigDecimal.valueOf(1));
}
return Chart.of(minValue, maxValue, goalInKg, dataPoints, calculareTrend(dataPoints));
}
示例5: howManyCandies2
import java.math.BigDecimal; //导入方法依赖的package包/类
public static void howManyCandies2() {
final BigDecimal TEN_CENTS = new BigDecimal(".10");
int itemsBought = 0;
BigDecimal funds = new BigDecimal("1.00");
for (BigDecimal price = TEN_CENTS; funds.compareTo(price) >= 0; price = price
.add(TEN_CENTS)) {
itemsBought++;
funds = funds.subtract(price);
}
System.out.println(itemsBought + " items bought.");
System.out.println("Money left over: $" + funds);
}
示例6: calculateReturnArkAmount
import java.math.BigDecimal; //导入方法依赖的package包/类
public BigDecimal calculateReturnArkAmount(BigDecimal sentArkAmount, BigDecimal usedArkAmount) {
BigDecimal delta = sentArkAmount.subtract(usedArkAmount);
if (delta.compareTo(BigDecimal.ZERO) > 0) {
return delta;
} else {
return BigDecimal.ZERO;
}
}
示例7: testItem_0050
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0050()
{
BigDecimal alpha = new BigDecimal("1000").setScale(0);
BigDecimal beta = new BigDecimal("0.70");
BigDecimal gamma = alpha.subtract(beta);
gamma.setScale(2, BigDecimal.ROUND_DOWN);
Assert.assertEquals("999.30", gamma.toString());
}
示例8: match
import java.math.BigDecimal; //导入方法依赖的package包/类
void match(String orderId, BigDecimal qty) {
BigDecimal origQty = orders.get(orderId);
if (origQty != null) {
BigDecimal newQty = origQty.subtract(qty);
orders.put(orderId, newQty);
totalSize = totalSize.subtract(qty);
}
}
示例9: bnm
import java.math.BigDecimal; //导入方法依赖的package包/类
BigDecimal bnm(BigDecimal x, BigDecimal error){
BigDecimal ret=BigDecimal.ONE;
BigDecimal z = x.subtract(ret);
BigDecimal step=BigDecimal.ZERO;
BigDecimal mistake=BigDecimal.ONE;
BigDecimal Al=y.toBigDecimal();
while(mistake.abs().compareTo(error)>0){
step=step.add(BigDecimal.ONE);
mistake=mistake.multiply(z,jc.MC).multiply(Al.subtract(step.subtract(BigDecimal.ONE),jc.MC),jc.MC).divide(step,jc.MC);
ret=ret.add(mistake,jc.MC);
}
return ret;
}
示例10: testItem_0053
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0053()
{
BigDecimal alpha = new BigDecimal(new BigInteger("1000"), 0);
BigDecimal beta = new BigDecimal(new BigInteger("70"), 2);
BigDecimal gamma = alpha.subtract(beta);
gamma.setScale(2, BigDecimal.ROUND_DOWN);
Assert.assertEquals("999.30", gamma.toString());
}
示例11: testItem_0055
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0055()
{
BigDecimal alpha = new BigDecimal(new BigInteger("1000"), 0);
BigDecimal beta = new BigDecimal(new BigInteger("70"), 2);
BigDecimal gamma = alpha.subtract(beta);
gamma.setScale(1);
Assert.assertEquals("999.30", gamma.toString());
}
示例12: bigDecimalToString_num
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_num(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < NUM_MAX_CHARS; numConverted++) {
cur = cur.multiply(NUM_ONE_PLACE);
int code = cur.intValue();
cur = cur.subtract(new BigDecimal(code));
int ch = numCodeToChar(code);
sb.append((char) ch);
}
return sb.toString();
}
示例13: bigDecimalToString_md5
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_md5(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MD5_MAX_CHARS; numConverted++) {
cur = cur.multiply(MD5_ONE_PLACE);
int code = cur.intValue();
cur = cur.subtract(new BigDecimal(code));
int ch = md5CodeToChar(code);
sb.append((char) ch);
}
return sb.toString();
}
示例14: exp
import java.math.BigDecimal; //导入方法依赖的package包/类
public static MFPNumeric exp(MFPNumeric a) {
if (a.mType == Type.MFP_NAN_VALUE) {
return MFPNumeric.NAN;
} else if (a.mType == Type.MFP_POSITIVE_INF) {
return MFPNumeric.INF;
} else if (a.isActuallyZero()) {
return MFPNumeric.ONE;
} else if (a.mType == Type.MFP_NEGATIVE_INF) {
return MFPNumeric.ZERO;
} else if (Math.abs(a.mdValue) <= POWER_EXPONENT_REASONABLE_ACCU_POS_RANGE_MAX) {
// use double to calculate, much quicker, and error should be less than 10**-15
return new MFPNumeric(Math.exp(a.mdValue));
} else if (a.mdValue <= EXP_TO_VALUE_RESULT_ZERO_THRESH) {
// a value is so small that result will be calculated as zero.
return MFPNumeric.ZERO;
} else {
// use bigDecimal.
BigDecimal bigDecResult = BigDecimal.ONE;
BigDecimal bigDecCurrentA = a.mbigDecimalValue;
int nAStep = (int)POWER_EXPONENT_BIG_DECIMAL_CALCULATION_STEP;
// first of all, calculate a**(b_1+b_2+...(int)b_m)
while (bigDecCurrentA.abs().compareTo(BigDecimal.ONE) >= 0) {
int nIntExponent = nAStep;
if (bigDecCurrentA.abs().compareTo(new BigDecimal(nAStep)) < 0) {
nIntExponent = (int)Math.abs(bigDecCurrentA.longValue());
}
BigDecimal bigDecComponent = MFPNumeric.E.mbigDecimalValue.pow(nIntExponent);
if (a.isActuallyPositive()) {
bigDecResult = bigDecResult.multiply(bigDecComponent);
bigDecCurrentA = bigDecCurrentA.subtract(new BigDecimal(nIntExponent));
} else { // a is negative. a is actually zero has been covered above.
bigDecResult = divide(bigDecResult, bigDecComponent);
bigDecCurrentA = bigDecCurrentA.add(new BigDecimal(nIntExponent));
}
}
// current A is between (-1, 1) and is not zero.
if (compareTo(bigDecCurrentA, BigDecimal.ZERO, 1) != 0) { // bigDecCurrentA is not actually 0
bigDecResult = bigDecResult.multiply(new BigDecimal(Math.exp(bigDecCurrentA.doubleValue())));
}
return new MFPNumeric(bigDecResult);
}
}
示例15: testItem_0021
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0021()
{
BigDecimal alpha = new BigDecimal("1000");
BigDecimal beta = new BigDecimal("0.70");
BigDecimal gamma = alpha.subtract(beta);
gamma.setScale(2);
Assert.assertEquals("999.30", gamma.toString());
}