java.math.BigDecimal.plus()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(312)

本文整理了Java中java.math.BigDecimal.plus()方法的一些代码示例,展示了BigDecimal.plus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.plus()方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:plus

BigDecimal.plus介绍

[英]Returns a new BigDecimal whose value is +this. The scale of the result is the same as the scale of this.
[中]返回一个新的BigDecimal,其值为+this。结果的比例与此的比例相同。

代码示例

代码示例来源:origin: stackoverflow.com

String doubleAsString = "23.23";
BigDecimal price = new BigDecimal(doubleAsString);
BigDecimal total = price.plus(anotherPrice);

代码示例来源:origin: deeplearning4j/nd4j

final BigDecimal xhighpr = scalePrec(x, 2);
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
BigDecimal resul = xhighpr.plus();

代码示例来源:origin: deeplearning4j/nd4j

final BigDecimal xhighpr = scalePrec(res, 2);
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
BigDecimal result = xhighpr.plus();

代码示例来源:origin: deeplearning4j/nd4j

BigDecimal resul = xhighpr.plus();

代码示例来源:origin: stackoverflow.com

class ThingCollectorHelper {
 BigDecimal sum1 = BigDecimal.ZERO;
 BigDecimal sum2 = BigDecimal.ZERO;
 void accept(Thing t) {
   if (t.field1 != null)
     sum1 = sum1.plus(t.field1);
   if (t.field2 != null)
     sum2 = sum2.plus(t.field2);
 }
 void combine(ThingCollectorHelper other) {
   sum1 = sum1.plus(other.sum1);
   sum2 = sum2.plus(other.sum2);
 }

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Returns a {@code BigDecimal} rounded according to the
 * {@code MathContext} settings.  If the precision setting is 0 then
 * no rounding takes place.
 *
 * <p>The effect of this method is identical to that of the
 * {@link #plus(MathContext)} method.
 *
 * @param mc the context to use.
 * @return a {@code BigDecimal} rounded according to the
 *         {@code MathContext} settings.
 * @throws ArithmeticException if the rounding mode is
 *         {@code UNNECESSARY} and the
 *         {@code BigDecimal}  operation would require rounding.
 * @see    #plus(MathContext)
 * @since  1.5
 */
public BigDecimal round(MathContext mc) {
  return plus(mc);
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Returns a {@code BigDecimal} rounded according to the
 * {@code MathContext} settings.  If the precision setting is 0 then
 * no rounding takes place.
 *
 * <p>The effect of this method is identical to that of the
 * {@link #plus(MathContext)} method.
 *
 * @param mc the context to use.
 * @return a {@code BigDecimal} rounded according to the
 *         {@code MathContext} settings.
 * @throws ArithmeticException if the rounding mode is
 *         {@code UNNECESSARY} and the
 *         {@code BigDecimal}  operation would require rounding.
 * @see    #plus(MathContext)
 * @since  1.5
 */
public BigDecimal round(MathContext mc) {
  return plus(mc);
}

代码示例来源:origin: stackoverflow.com

public class Account {
  private final List<Transaction> transactions = new ArrayList<Transaction>();
  private BigDecimal balance = BigDecimal.ZERO;

  public performTransaction(Transaction transaction) {
    transactions.add(transaction);
    balance = balance.plus(transaction.getDelta());
  }
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Returns a {@code BigDecimal} whose value is {@code (-this)},
 * with rounding according to the context settings.
 *
 * @param mc the context to use.
 * @return {@code -this}, rounded as necessary.
 * @throws ArithmeticException if the result is inexact but the
 *         rounding mode is {@code UNNECESSARY}.
 * @since  1.5
 */
public BigDecimal negate(MathContext mc) {
  return negate().plus(mc);
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Returns a {@code BigDecimal} whose value is {@code (-this)},
 * with rounding according to the context settings.
 *
 * @param mc the context to use.
 * @return {@code -this}, rounded as necessary.
 * @throws ArithmeticException if the result is inexact but the
 *         rounding mode is {@code UNNECESSARY}.
 * @since  1.5
 */
public BigDecimal negate(MathContext mc) {
  return negate().plus(mc);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Returns a {@code BigDecimal} whose value is the absolute value
 * of this {@code BigDecimal}, with rounding according to the
 * context settings.
 *
 * @param mc the context to use.
 * @return {@code abs(this)}, rounded as necessary.
 * @throws ArithmeticException if the result is inexact but the
 *         rounding mode is {@code UNNECESSARY}.
 * @since 1.5
 */
public BigDecimal abs(MathContext mc) {
  return (signum() < 0 ? negate(mc) : plus(mc));
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Returns a {@code BigDecimal} whose value is the absolute value
 * of this {@code BigDecimal}, with rounding according to the
 * context settings.
 *
 * @param mc the context to use.
 * @return {@code abs(this)}, rounded as necessary.
 * @throws ArithmeticException if the result is inexact but the
 *         rounding mode is {@code UNNECESSARY}.
 * @since 1.5
 */
public BigDecimal abs(MathContext mc) {
  return (signum() < 0 ? negate(mc) : plus(mc));
}

代码示例来源:origin: stackoverflow.com

public class Account {
  private Transaction[] transactions = new Transaction[0];
  private BigDecimal balance = BigDecimal.ZERO;

  public performTransaction(Transaction transaction) {
    transactions = transactions.copyOf(transactions, transactions.length + 1;
    transactions[transactions.length - 1] = transaction;
    balance = balance.plus(transaction.getDelta());
  }
}

public class Transaction {
  private final BigDecimal delta;

  public Transaction(BigDecimal delta) {
    this.delta = delta;
  }

  public BigDecimal getDelta() {
    return delta;
  }
}

代码示例来源:origin: optimatika/ojAlgo

/**
 * Will first enforce the precision, and then the scale. Both operations will comply with the rounding
 * mode.
 */
public BigDecimal enforce(final BigDecimal number) {
  BigDecimal tmpDecimal = number;
  if (myMathContext.getPrecision() > 0) {
    tmpDecimal = tmpDecimal.plus(this.getMathContext());
  }
  return this.scale(tmpDecimal);
}

代码示例来源:origin: org.ojalgo/ojalgo

/**
 * Will first enforce the precision, and then the scale. Both operations will comply with the rounding
 * mode.
 */
public BigDecimal enforce(final BigDecimal number) {
  BigDecimal tmpDecimal = number;
  if (myMathContext.getPrecision() > 0) {
    tmpDecimal = tmpDecimal.plus(this.getMathContext());
  }
  return this.scale(tmpDecimal);
}

代码示例来源:origin: org.nd4j/nd4j-common

final BigDecimal xhighpr = scalePrec(x, 2);
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
BigDecimal resul = xhighpr.plus();

代码示例来源:origin: org.nd4j/nd4j-common

final BigDecimal xhighpr = scalePrec(res, 2);
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
BigDecimal result = xhighpr.plus();

代码示例来源:origin: org.nd4j/nd4j-common

BigDecimal resul = xhighpr.plus();

相关文章

微信公众号

最新文章

更多