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

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

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

BigDecimal.unscaledValue介绍

[英]Returns the unscaled value (mantissa) of this BigDecimal instance as a BigInteger. The unscaled value can be computed as this * 10scale.
[中]将此BigDecimal实例的未标度值(尾数)作为BigInteger返回。未标度值可按此*10标度计算。

代码示例

代码示例来源:origin: prestodb/presto

public static SqlDecimal of(String decimalValue)
{
  BigDecimal bigDecimal = new BigDecimal(decimalValue);
  return new SqlDecimal(bigDecimal.unscaledValue(), bigDecimal.precision(), bigDecimal.scale());
}

代码示例来源:origin: prestodb/presto

public static Decimal toMetastoreDecimal(BigDecimal decimal)
{
  return new Decimal(ByteBuffer.wrap(decimal.unscaledValue().toByteArray()), (short) decimal.scale());
}

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

private byte[] convertFromDecimal(Schema schema, BigDecimal decimal) {
  final LogicalType logicalType = schema.getLogicalType();
  if (logicalType instanceof LogicalTypes.Decimal) {
    final LogicalTypes.Decimal decimalType = (LogicalTypes.Decimal) logicalType;
    // rescale to target type
    final BigDecimal rescaled = decimal.setScale(decimalType.getScale(), BigDecimal.ROUND_UNNECESSARY);
    // byte array must contain the two's-complement representation of the
    // unscaled integer value in big-endian byte order
    return decimal.unscaledValue().toByteArray();
  } else {
    throw new RuntimeException("Unsupported decimal type.");
  }
}

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

public static Decimal createThriftDecimal(String s) {
 BigDecimal d = new BigDecimal(s);
 return new Decimal((short) d.scale(), ByteBuffer.wrap(d.unscaledValue().toByteArray()));
}

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

public void setSafe(int index, BigDecimal value) {
 byte[] bytes = value.unscaledValue().toByteArray();
 setSafe(index, bytes, 0, bytes.length);
}

代码示例来源:origin: prestodb/presto

public static SqlDecimal of(String decimalValue)
{
  BigDecimal bigDecimal = new BigDecimal(decimalValue);
  return new SqlDecimal(bigDecimal.unscaledValue(), bigDecimal.precision(), bigDecimal.scale());
}

代码示例来源:origin: prestodb/presto

public StatisticsHasher putOptionalBigDecimal(BigDecimal value)
{
  hasher.putBoolean(value != null);
  if (value != null) {
    // this should really be 128 bits
    hasher.putInt(value.scale());
    hasher.putBytes(value.unscaledValue().toByteArray());
  }
  return this;
}

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

public void set(int index, BigDecimal value) {
 byte[] bytes = value.unscaledValue().toByteArray();
 set(index, bytes, 0, bytes.length);
}

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

/**
 * Updates the value of this object with the given {@link BigDecimal}. 
 * @param bigDecimal
 *    {@link java.math.BigDecimal}
 */
 public Decimal128 update(BigDecimal bigDecimal) {
  return update(bigDecimal.unscaledValue(), (short) bigDecimal.scale());
 }

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

/**
 * Convert a BigDecimal value to a byte array
 *
 * @param val
 * @return the byte array
 */
public static byte[] toBytes(BigDecimal val) {
  byte[] valueBytes = val.unscaledValue().toByteArray();
  byte[] result = new byte[valueBytes.length + SIZEOF_INT];
  int offset = putInt(result, 0, val.scale());
  putBytes(result, offset, valueBytes, 0, valueBytes.length);
  return result;
}

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

DateTime.parse("2014-03-01T12:12:12.321Z"),
123456L,
ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()), // 20.00
new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray())); // 20.00

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

int scale = v.scale();
int expOffset = scale % 2 * (scale < 0 ? -1 : 1);
int multiplyBy;
BigInteger bi = v.unscaledValue();

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

/**
 * Convert a BigDecimal value to a byte array
 *
 * @param val
 * @return the byte array
 */
public static byte[] toBytes(BigDecimal val) {
 byte[] valueBytes = val.unscaledValue().toByteArray();
 byte[] result = new byte[valueBytes.length + SIZEOF_INT];
 int offset = putInt(result, 0, val.scale());
 putBytes(result, offset, valueBytes, 0, valueBytes.length);
 return result;
}

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

public static User generateRandomUser(Random rnd) {
  return new User(
      generateRandomString(rnd, 50),
      rnd.nextBoolean() ? null : rnd.nextInt(),
      rnd.nextBoolean() ? null : generateRandomString(rnd, 6),
      rnd.nextBoolean() ? null : rnd.nextLong(),
      rnd.nextDouble(),
      null,
      rnd.nextBoolean(),
      generateRandomStringList(rnd, 20, 30),
      generateRandomBooleanList(rnd, 20),
      rnd.nextBoolean() ? null : generateRandomStringList(rnd, 20, 20),
      generateRandomColor(rnd),
      new HashMap<>(),
      generateRandomFixed16(rnd),
      generateRandomUnion(rnd),
      generateRandomAddress(rnd),
      generateRandomBytes(rnd),
      LocalDate.parse("2014-03-01"),
      LocalTime.parse("12:12:12"),
      123456,
      DateTime.parse("2014-03-01T12:12:12.321Z"),
      123456L,
      ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()),
      new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
}

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

String intString = bd.unscaledValue().toString();
int scale = bd.scale();

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

@Override
public ByteBuffer toBytes(BigDecimal value, Schema schema, LogicalType type) {
 int scale = ((LogicalTypes.Decimal) type).getScale();
 if (scale != value.scale()) {
  throw new AvroTypeException("Cannot encode decimal with scale " +
    value.scale() + " as scale " + scale);
 }
 return ByteBuffer.wrap(value.unscaledValue().toByteArray());
}

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

@Test
public void testCopyDecimalRaw() {
 testCopy(LogicalTypes.decimal(9, 2).addToSchema(Schema.create(Schema.Type.BYTES)),
      ByteBuffer.wrap(new BigDecimal("-34.34").unscaledValue().toByteArray()),
      GenericData.get());                  // no conversions
}

代码示例来源:origin: kiegroup/optaplanner

this.to = to;
this.incrementUnit = incrementUnit;
int scale = from.scale();
if (scale != to.scale()) {
  throw new IllegalArgumentException("The " + getClass().getSimpleName()
      + " cannot have a to (" + to + ") scale (" + to.scale()
      + ") which is different than its from (" + from + ") scale (" + scale + ").");
if (!to.unscaledValue().subtract(from.unscaledValue()).remainder(incrementUnit.unscaledValue())
    .equals(BigInteger.ZERO)) {
  throw new IllegalArgumentException("The " + getClass().getSimpleName()

代码示例来源:origin: org.apache.avro/avro

@Override
public ByteBuffer toBytes(BigDecimal value, Schema schema, LogicalType type) {
 int scale = ((LogicalTypes.Decimal) type).getScale();
 if (scale != value.scale()) {
  throw new AvroTypeException("Cannot encode decimal with scale " +
    value.scale() + " as scale " + scale);
 }
 return ByteBuffer.wrap(value.unscaledValue().toByteArray());
}

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

@Override
  public User map(Tuple3<String, Integer, String> value) {
    User user = new User();
    user.setName(value.f0);
    user.setFavoriteNumber(value.f1);
    user.setFavoriteColor(value.f2);
    user.setTypeBoolTest(true);
    user.setTypeArrayString(Collections.emptyList());
    user.setTypeArrayBoolean(Collections.emptyList());
    user.setTypeEnum(Colors.BLUE);
    user.setTypeMap(Collections.emptyMap());
    user.setTypeBytes(ByteBuffer.allocate(10));
    user.setTypeDate(LocalDate.parse("2014-03-01"));
    user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
    user.setTypeTimeMicros(123456);
    user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
    user.setTypeTimestampMicros(123456L);
    // 20.00
    user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
    // 20.00
    user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
    return user;
  }
}

相关文章