本文整理汇总了Java中java.math.BigDecimal.unscaledValue方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.unscaledValue方法的具体用法?Java BigDecimal.unscaledValue怎么用?Java BigDecimal.unscaledValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.unscaledValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import java.math.BigDecimal; //导入方法依赖的package包/类
public ByteBuffer serialize(BigDecimal value)
{
if (value == null)
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
BigInteger bi = value.unscaledValue();
int scale = value.scale();
byte[] bibytes = bi.toByteArray();
ByteBuffer bytes = ByteBuffer.allocate(4 + bibytes.length);
bytes.putInt(scale);
bytes.put(bibytes);
bytes.rewind();
return bytes;
}
示例2: encodeInternal
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
ByteBuffer encodeInternal(BigDecimal input) {
BigInteger bi = input.unscaledValue();
int scale = input.scale();
byte[] bibytes = bi.toByteArray();
ByteBuffer bytes = ByteBuffer.allocate(4 + bibytes.length);
bytes.putInt(scale);
bytes.put(bibytes);
bytes.rewind();
return bytes;
}
示例3: writeDecimal
import java.math.BigDecimal; //导入方法依赖的package包/类
protected void writeDecimal(BigDecimal o, Type type) {
int scale = o.scale();
BigInteger bigint = o.unscaledValue();
byte[] bytearr = bigint.toByteArray();
writeByteArray(bytearr);
writeInt(scale);
}
示例4: unscaledValue
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigInteger unscaledValue(BigDecimal o) {
//#ifdef JAVA2FULL
return o.unscaledValue();
//#else
/*
int scale = o.scale();
return o.movePointRight(scale).toBigInteger();
*/
//#endif
}
示例5: writeBigDecimal
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Writes {@link BigDecimal} value. The written value can be read via {@link #readBigDecimal(DataInput)}.
*
* @param val Value.
* @param out Data output.
*
* @throws IOException if failed to write value.
*/
public static void writeBigDecimal(BigDecimal val, DataOutput out) throws IOException {
if (val.compareTo(BigDecimal.ZERO) == 0) {
out.writeByte(DECIMAL_ZERO);
} else if (val.compareTo(BigDecimal.ONE) == 0) {
out.writeByte(DECIMAL_ONE);
} else if (val.compareTo(BigDecimal.TEN) == 0) {
out.writeByte(DECIMAL_TEN);
} else {
int scale = val.scale();
BigInteger unscaled = val.unscaledValue();
int bits = unscaled.bitLength();
if (bits <= 63) {
if (scale == 0) {
out.writeByte(DECIMAL_SMALL_UNSCALED);
writeVarLong(unscaled.longValue(), out);
} else {
out.writeByte(DECIMAL_SMALL_SCALED);
writeVarIntUnsigned(scale, out);
writeVarLong(unscaled.longValue(), out);
}
} else {
byte[] bytes = unscaled.toByteArray();
out.writeByte(DECIMAL_BIG);
writeVarIntUnsigned(scale, out);
writeVarIntUnsigned(bytes.length, out);
out.write(bytes, 0, bytes.length);
}
}
}
示例6: write
import java.math.BigDecimal; //导入方法依赖的package包/类
public static void write(BigDecimal d, DataOutput out) throws IOException {
int scale = d.scale();
BigInteger bigIntPart = d.unscaledValue();
boolean fastpath = bigIntPart.compareTo(LONG_MAX_AS_BIGINT) < 0
&& bigIntPart .compareTo(LONG_MIN_AS_BIGINT) > 0;
out.writeInt(scale);
out.writeBoolean(fastpath);
if (fastpath) {
out.writeLong(bigIntPart.longValue());
} else {
Text.writeString(out, bigIntPart.toString());
}
}
示例7: toBigInteger
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* <p>BigInteger value of BigDecimal value.</p>
*
* @param value Value to convert.
* @param canBeNull Can returned value be null?
*
* @return BigInteger value of BigDecimal, possibly null.
*/
private static BigInteger toBigInteger(
BigDecimal value,
boolean canBeNull) {
if (canBeNull && value.signum() == 0) {
return null;
} else {
return value.unscaledValue();
}
}
示例8: getUnscaledValue
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigInteger getUnscaledValue(BigDecimal o) {
//#ifdef JAVA1TARGET
/*
int scale = o.scale();
return o.movePointRight(scale).toBigInteger();
*/
//#else
return o.unscaledValue();
//#endif
}
示例9: getUnscaledValue
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigInteger getUnscaledValue(BigDecimal o) {
//#ifdef JAVA2FULL
return o.unscaledValue();
//#else
/*
int scale = o.scale();
return o.movePointRight(scale).toBigInteger();
*/
//#endif
}
示例10: toBigInteger
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* <p>BigInteger value of BigDecimal value.</p>
*
* @param value Value to convert.
* @param canBeNull Can returned value be null?
*
* @return BigInteger value of BigDecimal, possibly null.
*/
private static BigInteger toBigInteger(
BigDecimal value,
boolean canBeNull) {
if (canBeNull && value.signum() == 0) {
return null;
}
else {
return value.unscaledValue();
}
}