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

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

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

BigDecimal.signum介绍

[英]Returns the sign of this BigDecimal.
[中]返回此BigDecimal的符号。

代码示例

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

@Override
public int getSignum() {
  return value.signum();
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void setBigNumber( BigDecimal number ) {
 bool = number.signum() != 0;
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Constructs a Decimal128 value representing the given BigDecimal.
 *
 * @param value the Decimal128 value represented as a BigDecimal
 * @throws NumberFormatException if the value is out of the Decimal128 range
 */
public Decimal128(final BigDecimal value) {
  this(value, value.signum() == -1);
}

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

@Override
public int getSignum() {
  return value.signum();
}

代码示例来源:origin: alibaba/canal

private static int getLength(BigDecimal v) {
  int signum = v.signum();
  if (signum == 0) { // Special case for zero
    return 1;
  }
  return (signum < 0 ? 2 : 1) + (v.precision() + 1 + (v.scale() % 2 == 0 ? 0 : 1)) / 2;
}

代码示例来源:origin: pentaho/pentaho-kettle

protected Boolean convertBigNumberToBoolean( BigDecimal number ) {
 if ( number == null ) {
  return null;
 }
 return Boolean.valueOf( number.signum() != 0 );
}

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

/**
 * Returns a {@code BigDecimal} whose value is the absolute value of
 * {@code this}. The scale of the result is the same as the scale of this.
 */
public BigDecimal abs() {
  return ((signum() < 0) ? negate() : this);
}

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

public static BigDecimal round(BigDecimal value, BigDecimal increment,
                RoundingMode roundingMode) {
  if (increment.signum() == 0) {
    // 0 increment does not make much sense, but prevent division by 0
    return value;
  } else {
    BigDecimal divided = value.divide(increment, 0, roundingMode);
    BigDecimal result = divided.multiply(increment);
    return result;
  }
}

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

public static boolean isIntegerValue(BigDecimal value) {
    return value.signum() == 0
        || value.scale() <= 0
        || value.stripTrailingZeros().scale() <= 0;
  }
}

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

private boolean isIntegerValue(BigDecimal bd) {
 return bd.signum() == 0 || bd.scale() <= 0 || bd.stripTrailingZeros().scale() <= 0;
}

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

/**
 * Get the sign of the underlying decimal.
 * @return 0 if the decimal is equal to 0, -1 if less than zero, and 1 if greater than 0
 */
@HiveDecimalVersionV1
public int signum() {
 return bd.signum();
}

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

public OrderType getType() {
 return getAmount().signum() == -1 ? OrderType.BID : OrderType.ASK;
}

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

/**
 * Returns a {@code BigDecimal} whose value is the absolute value of
 * {@code this}. The result is rounded according to the passed context
 * {@code mc}.
 */
public BigDecimal abs(MathContext mc) {
  BigDecimal result = (signum() < 0) ? negate() : new BigDecimal(getUnscaledValue(), scale);
  result.inplaceRound(mc);
  return result;
}

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

public BigDecimal randHiveBigDecimalInverse(Random r, BigDecimal bigDecimal) {
 if (bigDecimal.signum() == 0) {
  return bigDecimal;
 }
 return BigDecimal.ONE.divide(bigDecimal);
}

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

@Override
public Value divide(Value v) {
  ValueDecimal dec = (ValueDecimal) v;
  if (dec.value.signum() == 0) {
    throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
  }
  BigDecimal bd = value.divide(dec.value,
      value.scale() + DIVIDE_SCALE_ADD,
      BigDecimal.ROUND_HALF_DOWN);
  if (bd.signum() == 0) {
    bd = BigDecimal.ZERO;
  } else if (bd.scale() > 0) {
    if (!bd.unscaledValue().testBit(0)) {
      bd = bd.stripTrailingZeros();
    }
  }
  return ValueDecimal.get(bd);
}

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

public OrderType getSide() {
 if (isTrade()) {
  switch (getAmount().signum()) {
   case 0:
   default:
    return null; // deposit or withdrawal
   case 1:
    return OrderType.BID;
   case -1:
    return OrderType.ASK;
  }
 } else {
  return null;
 }
}

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

public static Decimal28SparseHolder getDecimal28Holder(DrillBuf buf, BigDecimal bigDecimal) {
 Decimal28SparseHolder dch = new Decimal28SparseHolder();
 dch.scale = bigDecimal.scale();
 dch.precision = bigDecimal.precision();
 Decimal28SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
 dch.start = 0;
 dch.buffer = buf.reallocIfNeeded(5 * DecimalUtility.INTEGER_SIZE);
 DecimalUtility
  .getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, Decimal28SparseHolder.nDecimalDigits);
 return dch;
}

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

public static Decimal38SparseHolder getDecimal38Holder(DrillBuf buf, BigDecimal bigDecimal) {
 Decimal38SparseHolder dch = new Decimal38SparseHolder();
 dch.scale = bigDecimal.scale();
 dch.precision = bigDecimal.precision();
 Decimal38SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
 dch.start = 0;
 dch.buffer = buf.reallocIfNeeded(Decimal38SparseHolder.maxPrecision * DecimalUtility.INTEGER_SIZE);
 DecimalUtility
  .getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, Decimal38SparseHolder.nDecimalDigits);
 return dch;
}

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

@Override
public ValueDecimal modulus(Value v) {
  ValueDecimal dec = (ValueDecimal) v;
  if (dec.value.signum() == 0) {
    throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
  }
  BigDecimal bd = value.remainder(dec.value);
  return ValueDecimal.get(bd);
}

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

@Override
public ValueDecimal modulus(Value v) {
  ValueDecimal dec = (ValueDecimal) v;
  if (dec.value.signum() == 0) {
    throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
  }
  BigDecimal bd = value.remainder(dec.value);
  return ValueDecimal.get(bd);
}

相关文章

微信公众号

最新文章

更多