本文整理了Java中java.math.BigDecimal.stripTrailingZeros()
方法的一些代码示例,展示了BigDecimal.stripTrailingZeros()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.stripTrailingZeros()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:stripTrailingZeros
[英]Returns a new BigDecimal instance with the same value as this but with a unscaled value where the trailing zeros have been removed. If the unscaled value of this has n trailing zeros, then the scale and the precision of the result has been reduced by n.
[中]返回一个新的BigDecimal实例,该实例的值与此实例的值相同,但具有一个未缩放的值,其中尾部的零已被删除。如果未标度的值有n个尾随零,则结果的标度和精度降低了n。
代码示例来源:origin: kiegroup/optaplanner
@Override
public int hashCode() {
// A direct implementation (instead of HashCodeBuilder) to avoid dependencies
return (((((17 * 37)
+ initScore) * 37)
+ hardScore.stripTrailingZeros().hashCode()) * 37
+ mediumScore.stripTrailingZeros().hashCode()) * 37
+ softScore.stripTrailingZeros().hashCode();
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int hashCode() {
// A direct implementation (instead of HashCodeBuilder) to avoid dependencies
return ((17 * 37)
+ initScore) * 37
+ score.stripTrailingZeros().hashCode();
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int hashCode() {
// A direct implementation (instead of HashCodeBuilder) to avoid dependencies
int hashCode = (17 * 37) + initScore;
for (BigDecimal hardScore : hardScores) {
hashCode = (37 * hashCode) + hardScore.stripTrailingZeros().hashCode();
}
for (BigDecimal softScore : softScores) {
hashCode = (37 * hashCode) + softScore.stripTrailingZeros().hashCode();
}
return hashCode;
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int hashCode() {
// A direct implementation (instead of HashCodeBuilder) to avoid dependencies
return (((17 * 37)
+ initScore) * 37
+ hardScore.stripTrailingZeros().hashCode()) * 37
+ softScore.stripTrailingZeros().hashCode();
}
代码示例来源:origin: knowm/XChange
@Override
public void serialize(
final BigDecimal value, final JsonGenerator jgen, final SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeString(value.stripTrailingZeros().toPlainString());
}
}
代码示例来源:origin: org.hamcrest/hamcrest-all
private BigDecimal actualDelta(BigDecimal item) {
return item.subtract(value, MathContext.DECIMAL128).abs().subtract(delta, MathContext.DECIMAL128).stripTrailingZeros();
}
代码示例来源:origin: knowm/XChange
private int numberOfDecimals(String value) {
return new BigDecimal(value).stripTrailingZeros().scale();
}
代码示例来源:origin: web3j/web3j
public static boolean isIntegerValue(BigDecimal value) {
return value.signum() == 0
|| value.scale() <= 0
|| value.stripTrailingZeros().scale() <= 0;
}
}
代码示例来源:origin: apache/nifi
/**
* @param bytes to convert to GB
* @return BigDecimal bytes to GB
*/
public static BigDecimal convertBytesToGB(BigDecimal bytes) {
return bytes.divide(new BigDecimal(CONST_BYTES_GB_CONV), DIVIDE_SCALE, RoundingMode.HALF_UP).stripTrailingZeros();
}
代码示例来源:origin: apache/hive
private static BigDecimal trim(BigDecimal d) {
if (d.compareTo(BigDecimal.ZERO) == 0) {
// Special case for 0, because java doesn't strip zeros correctly on that number.
d = BigDecimal.ZERO;
} else {
d = d.stripTrailingZeros();
if (d.scale() < 0) {
// no negative scale decimals
d = d.setScale(0);
}
}
return d;
}
代码示例来源:origin: stackoverflow.com
@FacesConverter("bigDecimalPlainDisplay")
public class BigDecimalDisplayConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
throw new BigDecimal(value);
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
BigDecimal bd = (BigDecimal)value;
return bd.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
}
}
代码示例来源:origin: alibaba/easyexcel
public static String formatFloat(String value) {
if (null != value && value.contains(".")) {
if (isNumeric(value)) {
try {
BigDecimal decimal = new BigDecimal(value);
BigDecimal setScale = decimal.setScale(10, BigDecimal.ROUND_HALF_DOWN).stripTrailingZeros();
return setScale.toPlainString();
} catch (Exception e) {
}
}
}
return value;
}
代码示例来源:origin: stackoverflow.com
BigDecimal bigDecimal = BigDecimal.valueOf(100000.0)
.multiply(BigDecimal.valueOf(100d))
.stripTrailingZeros();
System.out.println("plain : " + bigDecimal.toPlainString());
System.out.println("scientific : " + bigDecimal.toEngineeringString());
代码示例来源:origin: web3j/web3j
private void confirmTransfer(
BigDecimal amountToTransfer, Convert.Unit transferUnit, BigDecimal amountInWei,
String destinationAddress) {
console.printf("Please confim that you wish to transfer %s %s (%s %s) to address %s%n",
amountToTransfer.stripTrailingZeros().toPlainString(), transferUnit,
amountInWei.stripTrailingZeros().toPlainString(),
Convert.Unit.WEI, destinationAddress);
String confirm = console.readLine("Please type 'yes' to proceed: ").trim();
if (!confirm.toLowerCase().equals("yes")) {
exitError("OK, some other time perhaps...");
}
}
代码示例来源:origin: alibaba/canal
private static byte[] encodeDecimal(Object object) {
if (object == null) {
return new byte[0];
}
BigDecimal v = (BigDecimal) object;
v = v.round(DEFAULT_MATH_CONTEXT).stripTrailingZeros();
int len = getLength(v);
byte[] result = new byte[Math.min(len, 21)];
decimalToBytes(v, result, 0, len);
return result;
}
代码示例来源:origin: knowm/XChange
/**
* The Ripple network transaction fee varies depending on how busy the network is as described <a
* href="https://wiki.ripple.com/Transaction_Fee">here</a>.
*
* @return current network transaction fee in units of XRP
*/
public BigDecimal getTransactionFee() {
return ripplePublic.getTransactionFee().getFee().stripTrailingZeros();
}
代码示例来源:origin: apache/hbase
/**
* Strip all trailing zeros to ensure that no digit will be zero and round
* using our default context to ensure precision doesn't exceed max allowed.
* From Phoenix's {@code NumberUtil}.
* @return new {@link BigDecimal} instance
*/
@VisibleForTesting
static BigDecimal normalize(BigDecimal val) {
return null == val ? null : val.stripTrailingZeros().round(DEFAULT_MATH_CONTEXT);
}
代码示例来源:origin: com.h2database/h2
@Override
public Value divide(Value v) {
ValueDecimal dec = (ValueDecimal) v;
if (dec.value.signum() == 0) {
throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
}
BigDecimal bd = value.divide(dec.value,
value.scale() + DIVIDE_SCALE_ADD,
BigDecimal.ROUND_HALF_DOWN);
if (bd.signum() == 0) {
bd = BigDecimal.ZERO;
} else if (bd.scale() > 0) {
if (!bd.unscaledValue().testBit(0)) {
bd = bd.stripTrailingZeros();
}
}
return ValueDecimal.get(bd);
}
代码示例来源:origin: knowm/XChange
public void verifyOrder(LimitOrder limitOrder) {
ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
verifyOrder(limitOrder, exchangeMetaData);
BigDecimal price = limitOrder.getLimitPrice().stripTrailingZeros();
if (price.scale()
> exchangeMetaData.getCurrencyPairs().get(limitOrder.getCurrencyPair()).getPriceScale()) {
throw new IllegalArgumentException("Unsupported price scale " + price.scale());
}
}
代码示例来源:origin: knowm/XChange
@Override
public BigDecimal getTransferFeeRate(final String address) throws RippleException, IOException {
final RippleAccountSettings accountSettings = getRippleAccountSettings(address);
return accountSettings.getSettings().getTransferFeeRate().stripTrailingZeros();
}
内容来源于网络,如有侵权,请联系作者删除!