本文整理汇总了Java中java.math.BigDecimal.stripTrailingZeros方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.stripTrailingZeros方法的具体用法?Java BigDecimal.stripTrailingZeros怎么用?Java BigDecimal.stripTrailingZeros使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.stripTrailingZeros方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bigDecimalToString_assci
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_assci(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
cur = cur.multiply(ASSCI_ONE_PLACE);
int ch = cur.intValue();
if (0 == ch) {
break;
}
cur = cur.subtract(new BigDecimal(ch));
//替换特殊字符
if (ch < 33) {
ch = 33;
} else if (ch == 127) {
ch = 126;
}
sb.append((char) ch);
}
return sb.toString();
}
示例2: bigDecimalToString_all
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Return the string encoded in a BigDecimal.
* Repeatedly multiply the input value by 65536; the integer portion after
* such a multiplication represents a single character in base 65536.
* Convert that back into a char and create a string out of these until we
* have no data left.
*/
public String bigDecimalToString_all(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
cur = cur.multiply(ONE_PLACE);
int curCodePoint = cur.intValue();
if (0 == curCodePoint) {
break;
}
cur = cur.subtract(new BigDecimal(curCodePoint));
//changed by Dbus team
sb.append(TextSplitter.toChars(curCodePoint));
}
return sb.toString();
}
示例3: bigDecimalToString
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Return the string encoded in a BigDecimal.
* Repeatedly multiply the input value by 65536; the integer portion after
* such a multiplication represents a single character in base 65536.
* Convert that back into a char and create a string out of these until we
* have no data left.
*/
public String bigDecimalToString(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
cur = cur.multiply(ONE_PLACE);
int curCodePoint = cur.intValue();
if (0 == curCodePoint) {
break;
}
cur = cur.subtract(new BigDecimal(curCodePoint));
sb.append(Character.toChars(curCodePoint));
}
return sb.toString();
}
示例4: bigDecimalToString
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Return the string encoded in a BigDecimal.
* Repeatedly multiply the input value by 65536; the integer portion after such a multiplication
* represents a single character in base 65536. Convert that back into a char and create a
* string out of these until we have no data left.
*/
String bigDecimalToString(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
cur = cur.multiply(ONE_PLACE);
int curCodePoint = cur.intValue();
if (0 == curCodePoint) {
break;
}
cur = cur.subtract(new BigDecimal(curCodePoint));
sb.append(Character.toChars(curCodePoint));
}
return sb.toString();
}
示例5: encodeBinary
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public final void encodeBinary(final BigDecimal value, final BufferWriter b) {
final BigDecimal minimized = value.stripTrailingZeros();
final BigInteger unscaled = minimized.abs().unscaledValue();
final int sign = minimized.signum();
final int beforeDecimal = minimized.precision() - minimized.scale();
// the decimal point must align on a base-10000 digit
final int padZeroes = 4 - minimized.scale() % 4;
BigInteger paddedUnscaled;
if (padZeroes == 0)
paddedUnscaled = unscaled;
else
paddedUnscaled = unscaled.multiply(BigInteger.valueOf(10).pow(padZeroes));
final short[] digits = findDigits(paddedUnscaled, EMPTY_SHORT_ARRAY);
int weight;
if (digits.length != 0) {
int firstDigitSize;
if (digits[0] < 10)
firstDigitSize = 1;
else if (digits[0] < 100)
firstDigitSize = 2;
else if (digits[0] < 1000)
firstDigitSize = 3;
else
firstDigitSize = 4;
weight = (beforeDecimal - firstDigitSize) / 4;
} else
weight = 0;
b.writeShort((short) digits.length);
b.writeShort((short) weight);
b.writeShort(sign < 0 ? NUMERIC_NEG : NUMERIC_POS);
b.writeShort((short) value.scale());
for (final short digit : digits)
b.writeShort(digit);
}
示例6: bigDecimalToString_num
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_num(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < NUM_MAX_CHARS; numConverted++) {
cur = cur.multiply(NUM_ONE_PLACE);
int code = cur.intValue();
cur = cur.subtract(new BigDecimal(code));
int ch = numCodeToChar(code);
sb.append((char) ch);
}
return sb.toString();
}
示例7: bigDecimalToString_md5
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_md5(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MD5_MAX_CHARS; numConverted++) {
cur = cur.multiply(MD5_ONE_PLACE);
int code = cur.intValue();
cur = cur.subtract(new BigDecimal(code));
int ch = md5CodeToChar(code);
sb.append((char) ch);
}
return sb.toString();
}
示例8: columnToValue
import java.math.BigDecimal; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private Comparable columnToValue(ResultSet resultSet, int columnIndex, int columnType) throws SQLException {
if (columnTypeIsString(columnType)) {
return resultSet.getString(columnIndex);
} else if (columnTypeIsNumeric(columnType)) {
BigDecimal bigDecimal = resultSet.getBigDecimal(columnIndex);
return bigDecimal == null ? null : bigDecimal.stripTrailingZeros();
} else if (columnTypeIsBoolean(columnType)) {
return resultSet.getBoolean(columnIndex);
} else if (columnTypeIsDate(columnType)) {
return resultSet.getDate(columnIndex);
} else {
throw new IllegalArgumentException("Column type " + columnType + " not supported for comparison");
}
}
示例9: ValueNumber
import java.math.BigDecimal; //导入方法依赖的package包/类
private ValueNumber(BigDecimal value) {
// important: need to normalize the BigDecimal here, otherwise 2.0 != 2.00
// (cannot use #compareTo() in an equals() method, because then hash codes would be incorrect)
super(value.stripTrailingZeros());
}
示例10: truncate
import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal truncate(final String text) {
BigDecimal bigDecimal = new BigDecimal(text);
if (bigDecimal.scale() > 2)
bigDecimal = new BigDecimal(text).setScale(2, RoundingMode.HALF_UP);
return bigDecimal.stripTrailingZeros();
}
示例11: convertToFraction
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Converts a value for this field to a fraction between 0 and 1.
* <p>
* The fractional value is between 0 (inclusive) and 1 (exclusive).
* It can only be returned if the {@link java.time.temporal.TemporalField#range() value range} is fixed.
* The fraction is obtained by calculation from the field range using 9 decimal
* places and a rounding mode of {@link RoundingMode#FLOOR FLOOR}.
* The calculation is inaccurate if the values do not run continuously from smallest to largest.
* <p>
* For example, the second-of-minute value of 15 would be returned as 0.25,
* assuming the standard definition of 60 seconds in a minute.
*
* @param value the value to convert, must be valid for this rule
* @return the value as a fraction within the range, from 0 to 1, not null
* @throws DateTimeException if the value cannot be converted to a fraction
*/
private BigDecimal convertToFraction(long value) {
ValueRange range = field.range();
range.checkValidValue(value, field);
BigDecimal minBD = BigDecimal.valueOf(range.getMinimum());
BigDecimal rangeBD = BigDecimal.valueOf(range.getMaximum()).subtract(minBD).add(BigDecimal.ONE);
BigDecimal valueBD = BigDecimal.valueOf(value).subtract(minBD);
BigDecimal fraction = valueBD.divide(rangeBD, 9, RoundingMode.FLOOR);
// stripTrailingZeros bug
return fraction.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : fraction.stripTrailingZeros();
}