java.math.BigDecimal.movePointLeft()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中java.math.BigDecimal.movePointLeft()方法的一些代码示例,展示了BigDecimal.movePointLeft()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.movePointLeft()方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:movePointLeft

BigDecimal.movePointLeft介绍

[英]Returns a new BigDecimal instance where the decimal point has been moved n places to the left. If n < 0 then the decimal point is moved -n places to the right.

The result is obtained by changing its scale. If the scale of the result becomes negative, then its precision is increased such that the scale is zero.

Note, that movePointLeft(0) returns a result which is mathematically equivalent, but which has scale >= 0.
[中]返回一个新的BigDecimal实例,其中小数点已向左移动n位。如果n<0,则小数点向右移动-n位。
结果是通过改变其比例得到的。如果结果的刻度变为负值,则其精度将增加,使刻度为零。
请注意,movePointLeft(0)返回的结果在数学上是等价的,但其比例>=0。

代码示例

代码示例来源:origin: knowm/XChange

public static BigDecimal percentToFactor(BigDecimal percent) {
  int PERCENT_DECIMAL_SHIFT = 2;
  return percent.movePointLeft(PERCENT_DECIMAL_SHIFT);
 }
}

代码示例来源:origin: knowm/XChange

public static BigDecimal percentToFactor(BigDecimal percent) {
 return percent.movePointLeft(PERCENT_DECIMAL_SHIFT);
}

代码示例来源:origin: knowm/XChange

protected static String getNow() {
  return String.valueOf(new BigDecimal(System.currentTimeMillis()).movePointLeft(3));
 }
}

代码示例来源:origin: Pay-Group/best-pay-sdk

/**
   * 分转元
   * @param fen
   * @return
   */
  public static Double Fen2Yuan(Integer fen) {
    return new BigDecimal(fen).movePointLeft(2).doubleValue();
  }
}

代码示例来源:origin: knowm/XChange

@Override
 public BigDecimal deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
  return new BigDecimal(jp.getValueAsLong()).movePointLeft(8);
 }
}

代码示例来源:origin: knowm/XChange

public static CoinbaseMoney getCoinbaseMoneyFromCents(JsonNode node) {
 final String amount = node.path("cents").asText();
 final String currency = node.path("currency_iso").asText();
 final int numDecimals = (currency.equalsIgnoreCase("BTC")) ? 8 : 2;
 return new CoinbaseMoney(currency, new BigDecimal(amount).movePointLeft(numDecimals));
}

代码示例来源:origin: spotbugs/spotbugs

@ExpectWarning("RV_RETURN_VALUE_IGNORED")
void bug2(BigDecimal any1, int anyInt) {
  any1.movePointLeft(anyInt);
}

代码示例来源:origin: knowm/XChange

private static void raw(BitsoAccountServiceRaw accountService) throws IOException {

  BitsoBalance bitsoBalance = accountService.getBitsoBalance();
  System.out.println("Bitso balance: " + bitsoBalance);

  BitsoDepositAddress depositAddress = accountService.getBitsoBitcoinDepositAddress();
  System.out.println("Bitcoin deposit address: " + depositAddress);

  String withdrawResult =
    accountService.withdrawBitsoFunds(new BigDecimal(1).movePointLeft(4), "XXX");
  System.out.println("Bitso withdrawal response = " + withdrawResult);
 }
}

代码示例来源:origin: knowm/XChange

private static void generic(AccountService accountService) throws IOException {
 // Get the account information
 AccountInfo accountInfo = accountService.getAccountInfo();
 System.out.println("AccountInfo as String: " + accountInfo.toString());
 String depositAddress = accountService.requestDepositAddress(Currency.BTC);
 System.out.println("Deposit address: " + depositAddress);
 String withdrawResult =
   accountService.withdrawFunds(Currency.BTC, new BigDecimal(1).movePointLeft(4), "XXX");
 System.out.println("withdrawResult = " + withdrawResult);
}

代码示例来源:origin: knowm/XChange

private static void generic(AccountService accountService) throws IOException {
 // Get the account information
 AccountInfo wallet = accountService.getAccountInfo();
 System.out.println("Wallet as String: " + wallet.toString());
 String depositAddress = accountService.requestDepositAddress(Currency.BTC);
 System.out.println("Deposit address: " + depositAddress);
 String withdrawResult =
   accountService.withdrawFunds(Currency.BTC, new BigDecimal(1).movePointLeft(4), "XXX");
 System.out.println("withdrawResult = " + withdrawResult);
}

代码示例来源:origin: knowm/XChange

private static void raw(BitstampAccountServiceRaw accountService) throws IOException {

  // Get the account information
  BitstampBalance bitstampBalance = accountService.getBitstampBalance();
  System.out.println("BitstampBalance: " + bitstampBalance);

  BitstampDepositAddress depositAddress = accountService.getBitstampBitcoinDepositAddress();
  System.out.println("BitstampDepositAddress address: " + depositAddress);

  final List<DepositTransaction> unconfirmedDeposits = accountService.getUnconfirmedDeposits();
  System.out.println("Unconfirmed deposits:");
  for (DepositTransaction unconfirmedDeposit : unconfirmedDeposits) {
   System.out.println(unconfirmedDeposit);
  }

  final List<WithdrawalRequest> withdrawalRequests =
    accountService.getWithdrawalRequests(50000000l);
  System.out.println("Withdrawal requests:");
  for (WithdrawalRequest unconfirmedDeposit : withdrawalRequests) {
   System.out.println(unconfirmedDeposit);
  }

  BitstampWithdrawal withdrawResult =
    accountService.withdrawBtcFunds(new BigDecimal(1).movePointLeft(4), "XXX");
  System.out.println("BitstampBooleanResponse = " + withdrawResult);
 }
}

代码示例来源:origin: shyiko/mysql-binlog-connector-java

for (; shift + DIG_PER_DEC <= scale; shift += DIG_PER_DEC, offset += 4) {
  int i = bigEndianInteger(value, offset, 4);
  fp = fp.add(BigDecimal.valueOf(i).movePointLeft(shift + DIG_PER_DEC));
  fp = fp.add(BigDecimal.valueOf(i).movePointLeft(scale));

代码示例来源:origin: lealone/Lealone

@Override
public Value convertScale(boolean onlyToSmallerScale, int targetScale) {
  if (targetScale >= DEFAULT_SCALE) {
    return this;
  }
  if (targetScale < 0) {
    throw DbException.getInvalidValueException("scale", targetScale);
  }
  long n = nanos;
  BigDecimal bd = BigDecimal.valueOf(n);
  bd = bd.movePointLeft(9);
  bd = ValueDecimal.setScale(bd, targetScale);
  bd = bd.movePointRight(9);
  long n2 = bd.longValue();
  if (n2 == n) {
    return this;
  }
  return fromDateValueAndNanos(dateValue, n2);
}

代码示例来源:origin: stackoverflow.com

nextI = (i << 1) | 1;
  } while (duration < 100000000 && nextI > 0);
  return new BigDecimal((duration) * 1000 / i).movePointLeft(3);
} catch (Throwable e) {
  throw new RuntimeException(e);

代码示例来源:origin: knowm/XChange

new FeeTier(
  resultQuantity,
  new Fee(resultMakerFee.movePointLeft(2), resultTakerFee.movePointLeft(2))));

代码示例来源:origin: apache/drill

fractionalPart = fractionalPart.movePointLeft(MAX_DIGITS);
BigDecimal temp = fractionalPart.remainder(BigDecimal.ONE);

代码示例来源:origin: knowm/XChange

public static CurrencyPairMetaData toMarketMetaData(WexPairInfo info, WexMetaData wexMetaData) {
 int priceScale = info.getDecimals();
 BigDecimal minimumAmount = withScale(info.getMinAmount(), wexMetaData.amountScale);
 BigDecimal feeFraction = info.getFee().movePointLeft(2);
 return new CurrencyPairMetaData(feeFraction, minimumAmount, null, priceScale, null);
}

代码示例来源:origin: knowm/XChange

public static ExchangeMetaData adaptMetaData(
  BitfinexAccountInfosResponse[] bitfinexAccountInfos, ExchangeMetaData exchangeMetaData) {
 final Map<CurrencyPair, CurrencyPairMetaData> currencyPairs =
   exchangeMetaData.getCurrencyPairs();
 // lets go with the assumption that the trading fees are common across all trading pairs for
 // now.
 // also setting the taker_fee as the trading_fee for now.
 final CurrencyPairMetaData metaData =
   new CurrencyPairMetaData(
     bitfinexAccountInfos[0].getTakerFees().movePointLeft(2), null, null, null, null);
 currencyPairs
   .keySet()
   .parallelStream()
   .forEach(
     currencyPair ->
       currencyPairs.merge(
         currencyPair,
         metaData,
         (oldMetaData, newMetaData) ->
           new CurrencyPairMetaData(
             newMetaData.getTradingFee(),
             oldMetaData.getMinimumAmount(),
             oldMetaData.getMaximumAmount(),
             oldMetaData.getPriceScale(),
             oldMetaData.getFeeTiers())));
 return exchangeMetaData;
}

代码示例来源:origin: apache/hbase

while (abs.compareTo(E32) >= 0 && e <= 350) { abs = abs.movePointLeft(32); e +=16; }
while (abs.compareTo(E8) >= 0 && e <= 350) { abs = abs.movePointLeft(8); e+= 4; }
while (abs.compareTo(BigDecimal.ONE) >= 0 && e <= 350) { abs = abs.movePointLeft(2); e++; }

代码示例来源:origin: knowm/XChange

public static CurrencyPairMetaData toMarketMetaData(DSXPairInfo info) {
 int priceScale = info.getDecimalsPrice();
 BigDecimal minimumAmount = withScale(info.getMinAmount(), info.getDecimalVolume());
 BigDecimal maximumAmount = withScale(info.getMaxPrice(), info.getDecimalVolume());
 BigDecimal feeFraction = info.getFee().movePointLeft(2);
 return new CurrencyPairMetaData(feeFraction, minimumAmount, maximumAmount, priceScale, null);
}

相关文章

微信公众号

最新文章

更多