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

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

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

BigDecimal.scaleByPowerOfTen介绍

[英]Returns a new BigDecimal whose value is this * 10n. The scale of the result is this.scale() - n. The precision of the result is the precision of this.

This method has the same effect as #movePointRight, except that the precision is not changed.
[中]返回一个新的BigDecimal,其值为*10n。结果的规模是这样的。scale()-n。结果的精度就是这个的精度。
此方法的效果与#movePointRight相同,只是精度没有改变。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Gets GB left.
 */
public String getGbLeft() {
  long space = size;
  space/=1024L;   // convert to KB
  space/=1024L;   // convert to MB
  return new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString();
}

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

public Date getTimestampCreated() {
 return new Date(timestampCreated.scaleByPowerOfTen(3).longValue());
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Formats the give date object into an AWS Service format.
 */
public static String formatServiceSpecificDate(Date date) {
  if (date == null)
    return null;
  BigDecimal dateValue = BigDecimal.valueOf(date.getTime());
  return dateValue.scaleByPowerOfTen(0 - AWS_DATE_MILLI_SECOND_PRECISION)
      .toPlainString();
}

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

public Date getTimestamp() {
 return new Date(timestamp.scaleByPowerOfTen(3).longValue());
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Parses the given date string returned by the AWS service into a Date
 * object.
 */
public static Date parseServiceSpecificDate(String dateString) {
  if (dateString == null)
    return null;
  try {
    BigDecimal dateValue = new BigDecimal(dateString);
    return new Date(dateValue.scaleByPowerOfTen(
        AWS_DATE_MILLI_SECOND_PRECISION).longValue());
  } catch (NumberFormatException nfe) {
    throw new SdkClientException("Unable to parse date : "
        + dateString, nfe);
  }
}

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

public static Map<CurrencyPair, Fee> AdaptDynamicTradingFees(
  GeminiTrailingVolumeResponse volumeResponse, List<CurrencyPair> currencyPairs) {
 Map<CurrencyPair, Fee> result = new Hashtable<CurrencyPair, Fee>();
 BigDecimal bpsToFraction = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(4));
 Fee feeAcrossCurrencies =
   new Fee(
     volumeResponse.MakerFeeBPS.multiply(bpsToFraction),
     volumeResponse.TakerFeeBPS.multiply(bpsToFraction));
 for (CurrencyPair currencyPair : currencyPairs) {
  result.put(currencyPair, feeAcrossCurrencies);
 }
 return result;
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

int nanosOnly;
BigDecimal nanoseconds = seconds.scaleByPowerOfTen(9);
if (nanoseconds.precision() - nanoseconds.scale() <= 0) {
  nanosOnly = nanoseconds.subtract(new BigDecimal(secondsOnly).scaleByPowerOfTen(9)).intValue();

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

@HiveDecimalVersionV1
public HiveDecimalV1 scaleByPowerOfTen(int n) {
 return create(bd.scaleByPowerOfTen(n));
}

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

for (BitfinexTradingFeeResponse.BitfinexTradingFeeResponseRow responseRow : responseRows) {
 Currency currency = Currency.getInstance(responseRow.getCurrency());
 BigDecimal percentToFraction = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(2));
 Fee fee =
   new Fee(

代码示例来源:origin: deeplearning4j/nd4j

BigDecimal xby10 = x.scaleByPowerOfTen(-exSc);
BigDecimal expxby10 = exp(xby10);

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

BigDecimal dollars = new BigDecimal(cents).scaleByPowerOfTen(-2);
System.out.printf("\t\t%-16s %11.2f\n", category, dollars);

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
 * Formats the give date object into an AWS Service format.
 */
public static String formatServiceSpecificDate(Date date) {
  if (date == null)
    return null;
  BigDecimal dateValue = BigDecimal.valueOf(date.getTime());
  return dateValue.scaleByPowerOfTen(0 - AWS_DATE_MILLI_SECOND_PRECISION)
      .toPlainString();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Override
public AwsJsonWriter value(Date value) throws IOException {
  BigDecimal dateValue = BigDecimal.valueOf(value.getTime());
  writer.value(dateValue.scaleByPowerOfTen(NEGATIVE_THREE));
  return this;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Override
public AwsJsonWriter value(Date value) throws IOException {
  BigDecimal dateValue = BigDecimal.valueOf(value.getTime());
  writer.writeNumber(dateValue.scaleByPowerOfTen(NEGATIVE_THREE).toPlainString());
  return this;
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
 * Parses the given date string returned by the AWS service into a Date
 * object.
 */
public static Date parseServiceSpecificDate(String dateString) {
  if (dateString == null)
    return null;
  try {
    BigDecimal dateValue = new BigDecimal(dateString);
    return new Date(dateValue.scaleByPowerOfTen(
        AWS_DATE_MILLI_SECOND_PRECISION).longValue());
  } catch (NumberFormatException nfe) {
    throw new SdkClientException("Unable to parse date : "
        + dateString, nfe);
  }
}

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

/**
 * Produces a value half of a "step" forward in this expression's rounding scale.
 * For example with a scale of 2, "2.5" would be stepped forward to "2.505".
 */
protected final BigDecimal halfStepNextInScale(BigDecimal decimal) {
  BigDecimal step = BigDecimal.ONE.scaleByPowerOfTen(-getRoundingScale());
  BigDecimal halfStep = step.divide(BigDecimal.valueOf(2));
  return decimal.add(halfStep);
}

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

/**
 * Produces a value one "step" back in this expression's rounding scale.
 * For example with a scale of 2, "2.5" would be stepped back to "2.49".
 */
protected final BigDecimal stepPrevInScale(BigDecimal decimal) {
  BigDecimal step = BigDecimal.ONE.scaleByPowerOfTen(-getRoundingScale());
  return decimal.subtract(step);
}

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

/**
 * Produces a value half of a "step" back in this expression's rounding scale.
 * For example with a scale of 2, "2.5" would be stepped back to "2.495".
 */
protected final BigDecimal halfStepPrevInScale(BigDecimal decimal) {
  BigDecimal step = BigDecimal.ONE.scaleByPowerOfTen(-getRoundingScale());
  BigDecimal halfStep = step.divide(BigDecimal.valueOf(2));
  return decimal.subtract(halfStep);
}

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

/**
 * Produces a value one "step" forward in this expression's rounding scale.
 * For example with a scale of 2, "2.5" would be stepped forward to "2.51".
 */
protected final BigDecimal stepNextInScale(BigDecimal decimal) {
  BigDecimal step = BigDecimal.ONE.scaleByPowerOfTen(-getRoundingScale());
  return decimal.add(step);
}

代码示例来源:origin: resteasy/Resteasy

/**
* @return the quality value between zero and one with five decimal places after the point.
* @see "3.3 Computing overall quality values"
*/
public BigDecimal getOverallQuality()
{
 BigDecimal qt = BigDecimal.valueOf(mediaTypeQualityValue.intValue(), 3);
 BigDecimal qc = BigDecimal.valueOf(characterSetQualityValue.intValue(), 3);
 BigDecimal qe = BigDecimal.valueOf(encodingQualityValue.intValue(), 3);
 BigDecimal ql = BigDecimal.valueOf(languageQualityValue.intValue(), 3);
 assert qt.compareTo(BigDecimal.ZERO) >= 0 && qt.compareTo(BigDecimal.ONE) <= 0;
 assert qc.compareTo(BigDecimal.ZERO) >= 0 && qc.compareTo(BigDecimal.ONE) <= 0;
 assert qe.compareTo(BigDecimal.ZERO) >= 0 && qe.compareTo(BigDecimal.ONE) <= 0;
 assert ql.compareTo(BigDecimal.ZERO) >= 0 && ql.compareTo(BigDecimal.ONE) <= 0;
 BigDecimal result = qt;
 result = result.multiply(qc, MathContext.DECIMAL32);
 result = result.multiply(qe, MathContext.DECIMAL32);
 result = result.multiply(ql, MathContext.DECIMAL32);
 assert result.compareTo(BigDecimal.ZERO) >= 0 && result.compareTo(BigDecimal.ONE) <= 0;
 long round5 = result.scaleByPowerOfTen(5).longValue();
 result = BigDecimal.valueOf(round5, 5);
 assert result.compareTo(BigDecimal.ZERO) >= 0 && result.compareTo(BigDecimal.ONE) <= 0;
 return result;
}

相关文章