本文整理汇总了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);
}