當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal.unscaledValue方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:16,代碼來源:DecimalSerializer.java

示例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;
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:13,代碼來源:CqlMapper.java

示例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);
    }
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:10,代碼來源:RowOutputBinary.java

示例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
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:14,代碼來源:JavaSystem.java

示例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);
        }
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:42,代碼來源:CodecUtils.java

示例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());
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:15,代碼來源:BigDecimalSerializer.java

示例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();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:DurationImpl.java

示例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
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:14,代碼來源:JavaSystem.java

示例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
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:14,代碼來源:JavaSystem.java

示例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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:DurationImpl.java


注:本文中的java.math.BigDecimal.unscaledValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。