当前位置: 首页>>代码示例>>Java>>正文


Java BigDecimal.subtract方法代码示例

本文整理汇总了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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例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;
}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:17,代码来源:AverageStrategy.java

示例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;
}
 
开发者ID:scourgemancer,项目名称:graphing-loan-analyzer,代码行数:17,代码来源:Loan.java

示例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));
}
 
开发者ID:xabgesagtx,项目名称:fat-lining,代码行数:32,代码来源:ChartFactory.java

示例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);
}
 
开发者ID:turoDog,项目名称:effectiveJava,代码行数:14,代码来源:Arithmetic.java

示例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;
    }
}
 
开发者ID:bradyo,项目名称:ark-java-smart-bridge-listener,代码行数:9,代码来源:ArkService.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例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);
    }
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:9,代码来源:OrderBook.java

示例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;
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:14,代码来源:CalCpowb.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例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();
}
 
开发者ID:BriData,项目名称:DBus,代码行数:16,代码来源:TextSplitter.java

示例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();
}
 
开发者ID:BriData,项目名称:DBus,代码行数:16,代码来源:TextSplitter.java

示例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);
    }    
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:44,代码来源:MFPNumeric.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java


注:本文中的java.math.BigDecimal.subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。