org.bson.types.Decimal128.bigDecimalValue()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(167)

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

Decimal128.bigDecimalValue介绍

[英]Gets a BigDecimal that is equivalent to this Decimal128.
[中]获取一个与此小数128等效的BigDecimal。

代码示例

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

@Override
public double doubleValue() {
  return value.bigDecimalValue().doubleValue();
}

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

@Override
public long longValue() {
  return value.bigDecimalValue().longValue();
}

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

@Override
public int intValue() {
  return value.bigDecimalValue().intValue();
}

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

@Override
public BigDecimal decode(final BsonReader reader, final DecoderContext decoderContext) {
  return reader.readDecimal128().bigDecimalValue();
}

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

@Override
public BigDecimal read(JsonReader in) throws IOException {
 checkArgument(in instanceof BsonReader, "Should be BsonReader, not some other JsonReader");
 return ((BsonReader) in).unwrap().readDecimal128().bigDecimalValue();
}

代码示例来源:origin: MorphiaOrg/morphia

@Override
public Object decode(final Class<?> targetClass, final Object value, final MappedField optionalExtraInfo) {
  if (value == null) {
    return null;
  }
  if (value instanceof BigDecimal) {
    return value;
  }
  if (value instanceof Decimal128) {
    return ((Decimal128) value).bigDecimalValue();
  }
  if (value instanceof BigInteger) {
    return new BigDecimal(((BigInteger) value));
  }
  if (value instanceof Double) {
    return new BigDecimal(((Double) value));
  }
  if (value instanceof Long) {
    return new BigDecimal(((Long) value));
  }
  if (value instanceof Number) {
    return new BigDecimal(((Number) value).doubleValue());
  }
  return new BigDecimal(value.toString());
}

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

@Override
public Number getNumberValue() throws IOException {
 final BsonType type = type();
 switch (type) {
  case DOUBLE:
   return reader.readDouble();
  case INT32:
   return reader.readInt32();
  case INT64:
   return reader.readInt64();
  case DECIMAL128:
   return reader.readDecimal128().bigDecimalValue();
  case STRING:
   return new BigDecimal(reader.readString());
  default:
   throw new IllegalStateException(String.format("Can't convert %s to %s", type, Number.class.getName()));
 }
}

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

@Override
public double nextDouble() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case INT32:
  return delegate.readInt32();
 case INT64:
  return delegate.readInt64();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().doubleValue();
 default:
  return delegate.readDouble();
 }
}

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

@Override
public long nextLong() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case DOUBLE:
  return (long) delegate.readDouble();
 case INT32:
  return delegate.readInt32();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().longValueExact();
 default:
  return delegate.readInt64();
 }
}

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

@Override
public int nextInt() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case DOUBLE:
  return (int) delegate.readDouble();
 case INT64:
  return (int) delegate.readInt64();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().intValueExact();
 default:
  return delegate.readInt32();
 }
}

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

@Test
public void write() throws Exception {
 JsonObject obj = new JsonObject();
 BigInteger bigInteger = new BigInteger(Long.toString(Long.MAX_VALUE)).multiply(new BigInteger("128"));
 obj.addProperty("bigInteger", bigInteger);
 BigDecimal bigDecimal = new BigDecimal(Long.MAX_VALUE).multiply(new BigDecimal(1024));
 obj.addProperty("bigDecimal", bigDecimal);
 BsonDocument doc = Jsons.toBson(obj);
 check(doc.get("bigInteger").getBsonType()).is(BsonType.DECIMAL128);
 check(doc.get("bigInteger").asDecimal128().decimal128Value().bigDecimalValue().toBigInteger()).is(bigInteger);
 check(doc.get("bigDecimal").getBsonType()).is(BsonType.DECIMAL128);
 check(doc.get("bigDecimal").asDecimal128().decimal128Value().bigDecimalValue()).is(bigDecimal);
}

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

@Test
 public void bigNumbers() throws Exception {
  JsonObject obj = new JsonObject();
  BigInteger bigInteger = new BigInteger(Long.toString(Long.MAX_VALUE)).multiply(new BigInteger("128"));
  obj.addProperty("bigInteger", bigInteger);
  BigDecimal bigDecimal = new BigDecimal(Long.MAX_VALUE).multiply(new BigDecimal(1024));
  obj.addProperty("bigDecimal", bigDecimal);

  BsonDocument bson = Jsons.toBson(obj);
  check(bson.get("bigInteger").getBsonType()).is(BsonType.DECIMAL128);
  check(bson.get("bigInteger").asDecimal128().decimal128Value().bigDecimalValue().toBigInteger()).is(bigInteger);
  check(bson.get("bigDecimal").getBsonType()).is(BsonType.DECIMAL128);
  check(bson.get("bigDecimal").asDecimal128().decimal128Value().bigDecimalValue()).is(bigDecimal);

  check(Jsons.toGson(bson)).is(obj);
 }
}

代码示例来源:origin: ch.rasc/bsoncodec

@Override
public BigDecimal decode(BsonReader reader, DecoderContext decoderContext) {
  return reader.readDecimal128().bigDecimalValue();
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public Object decode(final Class<?> targetClass, final Object value, final MappedField optionalExtraInfo) {
  if (value == null) {
    return null;
  }
  if (value instanceof BigDecimal) {
    return value;
  }
  if (value instanceof Decimal128) {
    return ((Decimal128) value).bigDecimalValue();
  }
  if (value instanceof BigInteger) {
    return new BigDecimal(((BigInteger) value));
  }
  if (value instanceof Double) {
    return new BigDecimal(((Double) value));
  }
  if (value instanceof Long) {
    return new BigDecimal(((Long) value));
  }
  if (value instanceof Number) {
    return new BigDecimal(((Number) value).doubleValue());
  }
  return new BigDecimal(value.toString());
}

代码示例来源:origin: org.immutables/mongo

@Override
public BigDecimal read(JsonReader in) throws IOException {
 checkArgument(in instanceof BsonReader, "Should be BsonReader, not some other JsonReader");
 return ((BsonReader) in).unwrap().readDecimal128().bigDecimalValue();
}

代码示例来源:origin: org.immutables/mongo

@Override
public Number getNumberValue() throws IOException {
 final BsonType type = type();
 switch (type) {
  case DOUBLE:
   return reader.readDouble();
  case INT32:
   return reader.readInt32();
  case INT64:
   return reader.readInt64();
  case DECIMAL128:
   return reader.readDecimal128().bigDecimalValue();
  case STRING:
   return new BigDecimal(reader.readString());
  default:
   throw new IllegalStateException(String.format("Can't convert %s to %s", type, Number.class.getName()));
 }
}

代码示例来源:origin: org.immutables/mongo

@Override
public double nextDouble() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case INT32:
  return delegate.readInt32();
 case INT64:
  return delegate.readInt64();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().doubleValue();
 default:
  return delegate.readDouble();
 }
}

代码示例来源:origin: org.immutables/mongo

@Override
public long nextLong() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case DOUBLE:
  return (long) delegate.readDouble();
 case INT32:
  return delegate.readInt32();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().longValueExact();
 default:
  return delegate.readInt64();
 }
}

代码示例来源:origin: org.immutables/mongo

@Override
public int nextInt() throws IOException {
 switch (delegate.getCurrentBsonType()) {
 case DOUBLE:
  return (int) delegate.readDouble();
 case INT64:
  return (int) delegate.readInt64();
 case DECIMAL128:
  return delegate.readDecimal128().bigDecimalValue().intValueExact();
 default:
  return delegate.readInt32();
 }
}

代码示例来源:origin: michel-kraemer/bson4jackson

/**
 * Test if {@link BigDecimal} objects can be serialized as {@link Decimal128}s
 * @throws Exception if something goes wrong
 */
@Test
public void writeBigDecimalsAsDecimal128s() throws Exception {
  Map<String, Object> data = new LinkedHashMap<String, Object>();
  data.put("big", new BigDecimal("0.3"));
  BSONObject obj = generateAndParse(data);
  Double result = (Double)obj.get("big");
  //BigDecimal("0.3") does not equal 0.3!
  assertEquals(0.3, result, 0.000001);
  assertFalse(Double.valueOf(0.3).equals(result));
  data = new LinkedHashMap<String, Object>();
  data.put("big", new BigDecimal("0.3"));
  obj = generateAndParse(data,
      Feature.WRITE_BIGDECIMALS_AS_DECIMAL128);
  org.bson.types.Decimal128 strResult = (org.bson.types.Decimal128)obj.get("big");
  assertEquals(new BigDecimal("0.3"), strResult.bigDecimalValue());
}

相关文章