@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(); }
@Override public int hashCode() { // A direct implementation (instead of HashCodeBuilder) to avoid dependencies return ((17 * 37) + initScore) * 37 + score.stripTrailingZeros().hashCode(); }
@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; }
@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(); }
@Override public void serialize( final BigDecimal value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(value.stripTrailingZeros().toPlainString()); } }
private BigDecimal actualDelta(BigDecimal item) { return item.subtract(value, MathContext.DECIMAL128).abs().subtract(delta, MathContext.DECIMAL128).stripTrailingZeros(); }
private int numberOfDecimals(String value) { return new BigDecimal(value).stripTrailingZeros().scale(); }
public static boolean isIntegerValue(BigDecimal value) { return value.signum() == 0 || value.scale() <= 0 || value.stripTrailingZeros().scale() <= 0; } }
/** * @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(); }
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; }
@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(); } }
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; }
BigDecimal bigDecimal = BigDecimal.valueOf(100000.0) .multiply(BigDecimal.valueOf(100d)) .stripTrailingZeros(); System.out.println("plain : " + bigDecimal.toPlainString()); System.out.println("scientific : " + bigDecimal.toEngineeringString());
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..."); } }
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; }
/** * 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(); }
/** * 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); }
@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); }
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()); } }
@Override public BigDecimal getTransferFeeRate(final String address) throws RippleException, IOException { final RippleAccountSettings accountSettings = getRippleAccountSettings(address); return accountSettings.getSettings().getTransferFeeRate().stripTrailingZeros(); }