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

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

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

BigDecimal.divideToIntegralValue介绍

[英]Returns a new BigDecimal whose value is the integral part of this / divisor. The quotient is rounded down towards zero to the next integer. For example, 0.5/0.2 = 2.
[中]

代码示例

代码示例来源: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: 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. The rounding mode passed with the parameter {@code mc} is
 * not considered. But if the precision of {@code mc > 0} and the integral
 * part requires more digits, then an {@code ArithmeticException} is thrown.
 *
 * @param divisor
 *            value by which {@code this} is divided.
 * @param mc
 *            math context which determines the maximal precision of the
 *            result.
 * @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, MathContext mc) {
  BigDecimal quotAndRem[] = new BigDecimal[2];
  quotAndRem[0] = this.divideToIntegralValue(divisor, mc);
  quotAndRem[1] = this.subtract( quotAndRem[0].multiply(divisor) );
  return quotAndRem;
}

代码示例来源:origin: robovm/robovm

return this.divideToIntegralValue(divisor);

代码示例来源:origin: SeanDragon/protools

/**
 * 获取该数被除后的整数
 *
 * @param object
 *         因数
 *
 * @return 结果
 */
public Decimal getDivGetInteger(Object object) {
  return new Decimal(this.bigDecimal.divideToIntegralValue(new Decimal(object).getBigDecimal(), mathContext));
}

代码示例来源:origin: com.googlecode.cqengine/cqengine

@Override
  public BigDecimal getQuantizedValue(BigDecimal attributeValue) {
    return attributeValue
        .divideToIntegralValue(compressionFactor)
        .multiply(compressionFactor)
        .setScale(0, RoundingMode.DOWN);
  }
}

代码示例来源:origin: net.sourceforge.owlapi/pellet-core-ignazio1977

public BigInteger apply(BigDecimal... args) {
  if ( args.length != 2 )
    return null;
  if ( args[1].equals( BigDecimal.ZERO ) )
    return null;
  
  return args[0].divideToIntegralValue( args[1], MathContext.DECIMAL128 ).toBigIntegerExact();
}

代码示例来源:origin: Galigator/openllet

@Override
public BigInteger apply(final BigDecimal... args)
{
  if (args.length != 2)
    return null;
  if (args[1].equals(BigDecimal.ZERO))
    return null;
  return args[0].divideToIntegralValue(args[1], MathContext.DECIMAL128).toBigIntegerExact();
}

代码示例来源:origin: Galigator/openllet

@Override
public BigInteger apply(final BigDecimal... args)
{
  if (args.length != 2)
    return null;
  if (args[1].equals(BigDecimal.ZERO))
    return null;
  return args[0].divideToIntegralValue(args[1], MathContext.DECIMAL128).toBigIntegerExact();
}

代码示例来源:origin: com.github.ansell.pellet/pellet-common

public BigInteger apply(BigDecimal... args) {
  if ( args.length != 2 )
    return null;
  if ( args[1].equals( BigDecimal.ZERO ) )
    return null;
  
  return args[0].divideToIntegralValue( args[1], MathContext.DECIMAL128 ).toBigIntegerExact();
}

代码示例来源:origin: com.github.meirfaraj/gcAnalyser-lib

/**
 * Calculate the number of whole days (24 hour periods) for a given number of milliseconds.
 *
 * @param timestamp            Time in milliseconds.
 * @return the number of whole days.
 */
public static final int daysInMilliSeconds(final long timestamp) {
  final BigDecimal days = new BigDecimal(timestamp);
  return days.divideToIntegralValue(new BigDecimal(1000 * 60 * 60 * 24))
      .intValue();
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-dlight-tools

private static float percent(BigDecimal value, BigDecimal total) {
    if (BigDecimal.ZERO.compareTo(total) < 0) { // 0 < total
      if (value.compareTo(BigDecimal.ZERO) <= 0) { // value <= 0
        return 0f;
      } else {
        return value.multiply(PERCENT).divideToIntegralValue(total).floatValue();
      }
    } else {
      return 0f;
    }
  }
}

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

BigDecimal x = new BigDecimal("5521.0000000001");
x = x.add(new BigDecimal("-1").
       multiply(x.divideToIntegralValue(new BigDecimal("1.0"))));
System.out.println(x.toPlainString());

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

int digitsRemain = 4;

BigDecimal bd = new BigDecimal("12.3456");
int power = bd.precision() - digitsRemain;
BigDecimal unit = bd.ulp().scaleByPowerOfTen(power);
BigDecimal result = bd.divideToIntegralValue(unit).multiply(unit);

代码示例来源:origin: org.javamoney.moneta/moneta-core

@Override
public RoundedMoney divideToIntegralValue(Number divisor) {
  BigDecimal dec = number.divideToIntegralValue(MoneyUtils.getBigDecimal(divisor), Optional.ofNullable(
      monetaryContext.get(MathContext.class)).orElse(MathContext.DECIMAL64));
  return new RoundedMoney(dec, currency, rounding);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.saxon

public IntegerValue compute(AtomicValue a, AtomicValue b, XPathContext c) throws XPathException {
  if (a instanceof IntegerValue && b instanceof IntegerValue) {
    return ((IntegerValue) a).idiv((IntegerValue) b);
  }
  final BigDecimal A = ((NumericValue) a).getDecimalValue();
  final BigDecimal B = ((NumericValue) b).getDecimalValue();
  if (B.signum() == 0) {
    throw new XPathException("Integer division by zero", "FOAR0001", c);
  }
  //BigInteger quot = A.divide(B, 0, BigDecimal.ROUND_DOWN).toBigInteger();
  BigInteger quot = A.divideToIntegralValue(B).toBigInteger();
  return BigIntegerValue.makeIntegerValue(quot);
}

代码示例来源:origin: org.javamoney.moneta/moneta-core

@Override
public Money divideToIntegralValue(Number divisor) {
  if (NumberVerifier.isInfinityAndNotNaN(divisor)) {
    return Money.of(0, getCurrency());
  }
  MathContext mc = MoneyUtils.getMathContext(monetaryContext, RoundingMode.HALF_EVEN);
  BigDecimal divisorBD = MoneyUtils.getBigDecimal(divisor);
  BigDecimal dec = this.number.divideToIntegralValue(divisorBD, mc);
  return new Money(dec, getCurrency(), monetaryContext);
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyInteger idiv(ThreadContext context, RubyRational val) {
  if (isNaN()) throw newNaNFloatDomainError(context.runtime);
  if (isInfinity()) { // NOTE: MRI is inconsistent with div(other, d) impl
    throw newInfinityFloatDomainError(context.runtime, infinitySign);
  }
  if (val.isZero()) throw context.runtime.newZeroDivisionError();
  BigDecimal result = this.value.multiply(toBigDecimal(val.getDenominator()))
                 .divideToIntegralValue(toBigDecimal(val.getNumerator()));
  return toInteger(context.runtime, result);
}

代码示例来源:origin: org.jruby/jruby-core

private RubyInteger idiv(ThreadContext context, RubyRational val) {
  if (isNaN()) throw newNaNFloatDomainError(context.runtime);
  if (isInfinity()) { // NOTE: MRI is inconsistent with div(other, d) impl
    throw newInfinityFloatDomainError(context.runtime, infinitySign);
  }
  if (val.isZero()) throw context.runtime.newZeroDivisionError();
  BigDecimal result = this.value.multiply(toBigDecimal(val.getDenominator()))
                 .divideToIntegralValue(toBigDecimal(val.getNumerator()));
  return toInteger(context.runtime, result);
}

代码示例来源:origin: org.javamoney.moneta/moneta-core

@Override
public FastMoney divideToIntegralValue(Number divisor) {
  if (NumberVerifier.isInfinityAndNotNaN(divisor)) {
    return new FastMoney(0L, getCurrency());
  }
  checkNumber(divisor);
  if (isOne(divisor)) {
    return this;
  }
  BigDecimal div = MoneyUtils.getBigDecimal(divisor);
  return new FastMoney(getBigDecimal().divideToIntegralValue(div), getCurrency(), false);
}

代码示例来源:origin: zycgit/hasor

/** 小数,整除 */
private static Number decimalAliquot(Number obj1, Number obj2) {
  int maxType = getNumericType(obj1, obj2);
  switch (maxType) {
  case FLOAT:
    return newReal(maxType, (int) (floatValue(obj1) / floatValue(obj2)));
  case DOUBLE:
    return newReal(maxType, (long) (doubleValue(obj1) / doubleValue(obj2)));
  default:
    return newReal(maxType, bigDecimalValue(obj1).divideToIntegralValue(bigDecimalValue(obj2)));
  }
}
/** 小数,求余 */

相关文章

微信公众号

最新文章

更多