本文整理匯總了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) + "千米";
}
}
示例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);
}
}
示例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);
}