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

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

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

BigDecimal.movePointRight介绍

[英]Returns a new BigDecimal instance where the decimal point has been moved n places to the right. If n < 0 then the decimal point is moved -n places to the left.

The result is obtained by changing its scale. If the scale of the result becomes negative, then its precision is increased such that the scale is zero.

Note, that movePointRight(0) returns a result which is mathematically equivalent, but which has scale >= 0.
[中]返回一个新的BigDecimal实例,其中小数点已向右移动n位。如果n<0,则小数点向左移动-n位。
结果是通过改变其比例得到的。如果结果的刻度变为负值,则其精度将增加,使刻度为零。
请注意,movePointRight(0)返回的结果在数学上是等价的,但其比例>=0。

代码示例

代码示例来源:origin: knowm/XChange

@Override
 public void serialize(BigDecimal valueBtc, JsonGenerator gen, SerializerProvider serializers)
   throws IOException {
  gen.writeNumber(valueBtc.movePointRight(8));
 }
}

代码示例来源:origin: Pay-Group/best-pay-sdk

/**
 * 元转分
 * @param yuan
 * @return
 */
public static Integer Yuan2Fen(Double yuan) {
  return new BigDecimal(String.valueOf(yuan)).movePointRight(2).intValue();
}

代码示例来源:origin: google/ExoPlayer

final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());

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

public BigDecimal eval(List<? extends Number> parameters) {
    assertNotNull(parameters.get(0));
    /*
     * From The Java Programmers Guide To numerical Computing (Ronald Mak, 2003)
     */
    BigDecimal x = (BigDecimal) parameters.get(0);
    if (x.compareTo(BigDecimal.ZERO) == 0) {
      return new BigDecimal(0);
    }
    if (x.signum() < 0) {
      throw new ExpressionException("Argument to SQRT() function must not be negative");
    }
    BigInteger n = x.movePointRight(mc.getPrecision() << 1).toBigInteger();
    int bits = (n.bitLength() + 1) >> 1;
    BigInteger ix = n.shiftRight(bits);
    BigInteger ixPrev;
    BigInteger test;
    do {
      ixPrev = ix;
      ix = ix.add(n.divide(ix)).shiftRight(1);
      // Give other threads a chance to work;
      Thread.yield();
      test = ix.subtract(ixPrev).abs();
    } while (test.compareTo(BigInteger.ZERO) != 0 && test.compareTo(BigInteger.ONE) != 0);
    return new BigDecimal(ix, mc.getPrecision());
  }
});

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

/**
 * <p>Return millisecond precision of {@link #getFractionalSecond()}.</p>
 *
 * <p>This method represents a convenience accessor to infinite
 * precision fractional second value returned by
 * {@link #getFractionalSecond()}. The returned value is the rounded
 * down to milliseconds value of
 * {@link #getFractionalSecond()}. When {@link #getFractionalSecond()}
 * returns <code>null</code>, this method must return
 * {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
 *
 * <p>Value constraints for this value are summarized in
 * <a href="#datetimefield-second">second field of date/time field mapping table</a>.</p>
 *
 * @return Millisecond  of this <code>XMLGregorianCalendar</code>.
 *
 * @see #getFractionalSecond()
 * @see #setTime(int, int, int)
 */
public int getMillisecond() {
  BigDecimal fractionalSeconds = getFractionalSecond();
  // is field undefined?
  if (fractionalSeconds == null) {
    return DatatypeConstants.FIELD_UNDEFINED;
  }
  return getFractionalSecond().movePointRight(3).intValue();
}

代码示例来源:origin: jphp-group/jphp

initialGuess = BigDecimal.ONE.movePointRight(length);
cscale = Math.max(scale, value.scale()) + 2;

代码示例来源:origin: lealone/Lealone

@Override
public Value convertScale(boolean onlyToSmallerScale, int targetScale) {
  if (targetScale >= DEFAULT_SCALE) {
    return this;
  }
  if (targetScale < 0) {
    throw DbException.getInvalidValueException("scale", targetScale);
  }
  long n = nanos;
  BigDecimal bd = BigDecimal.valueOf(n);
  bd = bd.movePointLeft(9);
  bd = ValueDecimal.setScale(bd, targetScale);
  bd = bd.movePointRight(9);
  long n2 = bd.longValue();
  if (n2 == n) {
    return this;
  }
  return fromDateValueAndNanos(dateValue, n2);
}

代码示例来源:origin: shyiko/mysql-binlog-connector-java

for (; offset < ipSize; offset += 4) {
  int i = bigEndianInteger(value, offset, 4);
  ip = ip.movePointRight(DIG_PER_DEC).add(BigDecimal.valueOf(i));

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

l = b.movePointRight(4).longValue();
if (d >= Math.pow(10, -4) && d < 1) {
  requireScientificRepresentation = false;
  precision += 4 - String.valueOf(l).length();
  l = b.movePointRight(precision + 1).longValue();
  if (String.valueOf(l).length() <= formatToken.getPrecision()) {
    precision++;
  l = b.movePointRight(precision).longValue();
  if (l >= Math.pow(10, precision - 4)) {
    formatToken.setPrecision(precision);

代码示例来源:origin: com.h2database/h2

number = number.movePointRight(digits);
format = format.substring(0, v) + format.substring(v + 1);

代码示例来源:origin: apache/hbase

while (abs.compareTo(EN10) < 0) { abs = abs.movePointRight(8); e += 4; }
while (abs.compareTo(EN2) < 0) { abs = abs.movePointRight(2); e++; }
 abs = abs.movePointRight(2);
 d = abs.intValue();
 dst.put((byte) ((2 * d + 1) & 0xff));

代码示例来源:origin: apache/drill

BigDecimal fractionalPart = input.remainder(BigDecimal.ONE).movePointRight(scale);

代码示例来源:origin: jmdhappy/xxpay-master

long aliPayAmt = new BigDecimal(total_amount).movePointRight(2).longValue();
long dbPayAmt = payOrder.getAmount().longValue();
if (dbPayAmt != aliPayAmt) {

代码示例来源:origin: jmdhappy/xxpay-master

long aliPayAmt = new BigDecimal(total_amount).movePointRight(2).longValue();
long dbPayAmt = payOrder.getAmount().longValue();
if (dbPayAmt != aliPayAmt) {

代码示例来源:origin: jmdhappy/xxpay-master

long aliPayAmt = new BigDecimal(total_amount).movePointRight(2).longValue();
long dbPayAmt = payOrder.getAmount().longValue();
if (dbPayAmt != aliPayAmt) {

代码示例来源:origin: apache/hbase

abs = abs.movePointRight(2);
d = abs.intValue();
dst.put((byte) (2 * d + 1));

代码示例来源:origin: pholser/junit-quickcheck

@Override public void verifyInteractionWithRandomness() {
    verify(randomForParameterGenerator).nextBigInteger(
      minBigInt.add(TEN.movePointRight(7).toBigInteger()).subtract(minBigInt).bitLength());
    verify(randomForParameterGenerator).nextBigInteger(
      minBigInt.add(TEN.pow(2).movePointRight(7).toBigInteger()).subtract(minBigInt).bitLength());
  }
}

代码示例来源:origin: pholser/junit-quickcheck

@Override protected void primeSourceOfRandomness() {
  when(randomForParameterGenerator.nextBigInteger(
    minBigInt.add(TEN.movePointRight(8).toBigInteger()).subtract(minBigInt).bitLength()))
    .thenReturn(new BigInteger("6"));
  when(randomForParameterGenerator.nextBigInteger(
    minBigInt.add(TEN.pow(2).movePointRight(8).toBigInteger()).subtract(minBigInt).bitLength()))
    .thenReturn(new BigInteger("35"));
  when(distro.sampleWithMean(1, randomForParameterGenerator)).thenReturn(0);
  when(distro.sampleWithMean(2, randomForParameterGenerator)).thenReturn(1);
}

代码示例来源:origin: pholser/junit-quickcheck

@Override protected void primeSourceOfRandomness() {
  when(randomForParameterGenerator.nextBigInteger(
    minBigInt.add(TEN.movePointRight(7).toBigInteger()).subtract(minBigInt).bitLength()))
    .thenReturn(new BigInteger("6"));
  when(randomForParameterGenerator.nextBigInteger(
    minBigInt.add(TEN.pow(2).movePointRight(7).toBigInteger()).subtract(minBigInt).bitLength()))
    .thenReturn(new BigInteger("35"));
  when(distro.sampleWithMean(1, randomForParameterGenerator)).thenReturn(0);
  when(distro.sampleWithMean(2, randomForParameterGenerator)).thenReturn(1);
}

代码示例来源:origin: pholser/junit-quickcheck

@Override protected void primeSourceOfRandomness() {
  when(randomForParameterGenerator.nextBigInteger(
    maxBigInt.subtract(maxBigInt.subtract(TEN.movePointRight(5).toBigInteger())).bitLength()))
    .thenReturn(new BigInteger("6"));
  when(randomForParameterGenerator.nextBigInteger(
    maxBigInt.subtract(maxBigInt.subtract(TEN.pow(2).movePointRight(5).toBigInteger())).bitLength()))
    .thenReturn(new BigInteger("35"));
  when(distro.sampleWithMean(1, randomForParameterGenerator)).thenReturn(0);
  when(distro.sampleWithMean(2, randomForParameterGenerator)).thenReturn(1);
}

相关文章

微信公众号

最新文章

更多