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


Java BigDecimal.movePointLeft方法代碼示例

本文整理匯總了Java中java.math.BigDecimal.movePointLeft方法的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal.movePointLeft方法的具體用法?Java BigDecimal.movePointLeft怎麽用?Java BigDecimal.movePointLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.movePointLeft方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import java.math.BigDecimal; //導入方法依賴的package包/類
private Object convert(String text) {
    if (text == null) {
        return null;
    }
    BigDecimal paramData = new BigDecimal(text.toString()).setScale(0, BigDecimal.ROUND_HALF_UP);
    if (KM.compareTo(paramData) > 0) {
        return paramData + "米";
    } else {
        return paramData.movePointLeft(3) + "千米";
    }
}
 
開發者ID:ling49043171,項目名稱:mark-framework,代碼行數:12,代碼來源:DistanceTypeHandler.java

示例2: getSparseFromBigDecimal

import java.math.BigDecimal; //導入方法依賴的package包/類
public static void getSparseFromBigDecimal(BigDecimal input, DrillBuf data, int startIndex, int scale, int precision, int nDecimalDigits) {

        // Initialize the buffer
        for (int i = 0; i < nDecimalDigits; i++) {
          data.setInt(startIndex + (i * integerSize), 0);
        }

        boolean sign = false;

        if (input.signum() == -1) {
            // negative input
            sign = true;
            input = input.abs();
        }

        // Truncate the input as per the scale provided
        input = input.setScale(scale, BigDecimal.ROUND_HALF_UP);

        // Separate out the integer part
        BigDecimal integerPart = input.setScale(0, BigDecimal.ROUND_DOWN);

        int destIndex = nDecimalDigits - roundUp(scale) - 1;

        // we use base 1 billion integer digits for out integernal representation
        BigDecimal base = new BigDecimal(DIGITS_BASE);

        while (integerPart.compareTo(BigDecimal.ZERO) == 1) {
            // store the modulo as the integer value
            data.setInt(startIndex + (destIndex * integerSize), (integerPart.remainder(base)).intValue());
            destIndex--;
            // Divide by base 1 billion
            integerPart = (integerPart.divide(base)).setScale(0, BigDecimal.ROUND_DOWN);
        }

        /* Sparse representation contains padding of additional zeroes
         * so each digit contains MAX_DIGITS for ease of arithmetic
         */
        int actualDigits;
        if ((actualDigits = (scale % MAX_DIGITS)) != 0) {
            // Pad additional zeroes
            scale = scale + (MAX_DIGITS - actualDigits);
            input = input.setScale(scale, BigDecimal.ROUND_DOWN);
        }

        //separate out the fractional part
        BigDecimal fractionalPart = input.remainder(BigDecimal.ONE).movePointRight(scale);

        destIndex = nDecimalDigits - 1;

        while (scale > 0) {
            // Get next set of MAX_DIGITS (9) store it in the DrillBuf
            fractionalPart = fractionalPart.movePointLeft(MAX_DIGITS);
            BigDecimal temp = fractionalPart.remainder(BigDecimal.ONE);

            data.setInt(startIndex + (destIndex * integerSize), (temp.unscaledValue().intValue()));
            destIndex--;

            fractionalPart = fractionalPart.setScale(0, BigDecimal.ROUND_DOWN);
            scale -= MAX_DIGITS;
        }

        // Set the negative sign
        if (sign == true) {
            data.setInt(startIndex, data.getInt(startIndex) | 0x80000000);
        }

    }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:68,代碼來源:DecimalUtility.java

示例3: minimumIncrement

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
    * This probably should be Currency responsibility. Even then, it may need
    * to be customized for specialty apps because there are other cases, where
    * the smallest increment is not the smallest unit.
    */
Money minimumIncrement() {
	BigDecimal one = new BigDecimal(1);
	BigDecimal increment = one.movePointLeft(currency.getDefaultFractionDigits());
	return Money.valueOf(increment, currency);
}
 
開發者ID:neuhalje,項目名稱:TimeAndMoney,代碼行數:11,代碼來源:Money.java


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