java.math.MathContext.getRoundingMode()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(121)

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

MathContext.getRoundingMode介绍

[英]Returns the rounding mode. The rounding mode is the strategy to be used to round results.

The rounding mode is one of RoundingMode#UP, RoundingMode#DOWN, RoundingMode#CEILING, RoundingMode#FLOOR, RoundingMode#HALF_UP, RoundingMode#HALF_DOWN, RoundingMode#HALF_EVEN, or RoundingMode#UNNECESSARY.
[中]返回舍入模式。舍入模式是用于对结果进行舍入的策略。
四舍五入模式是四舍五入模式中的一种:向上、向下、天花板、地板、向上、向下、均匀或不必要。

代码示例

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

public BigDecimal eval(List<? extends Number> parameters) {
    assertNotNull(parameters.get(0), parameters.get(1));
    BigDecimal toRound = (BigDecimal) parameters.get(0);
    int precision = parameters.get(1).intValue();
    return toRound.setScale(precision, mc.getRoundingMode());
  }
});

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

/**
 * Returns true if x is a {@code MathContext} with the same precision
 * setting and the same rounding mode as this {@code MathContext} instance.
 *
 * @param x
 *            object to be compared.
 * @return {@code true} if this {@code MathContext} instance is equal to the
 *         {@code x} argument; {@code false} otherwise.
 */
@Override
public boolean equals(Object x) {
  return ((x instanceof MathContext)
      && (((MathContext) x).getPrecision() == precision) && (((MathContext) x)
      .getRoundingMode() == roundingMode));
}

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

mc.getRoundingMode());

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

mc.getRoundingMode());

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

mc.getRoundingMode());
if (compRem != 0) {
  integerAndFraction[0] = integerAndFraction[0].add(BigInteger.valueOf(compRem));

代码示例来源:origin: SeanDragon/protools

/**
 * 精确最多2位小数四舍五入转换为字符串
 *
 * @return
 */
public String moneyStrValue() {
  return fullStrValue(2, this.mathContext.getRoundingMode());
}

代码示例来源:origin: SeanDragon/protools

/**
 * 精确最多2位小数四舍五入
 *
 * @return
 */
public double moneyValue() {
  return doubleValue(2, this.mathContext.getRoundingMode());
}

代码示例来源:origin: SeanDragon/protools

/**
 * 传入进度和舍入原则进行double
 *
 * @param scale
 *         进度
 *
 * @return 结果
 */
public double doubleValue(int scale) {
  return this.doubleValue(scale, mathContext.getRoundingMode());
}

代码示例来源:origin: SeanDragon/protools

public String fullStrValue(int scale) {
  return this.fullStrValue(scale, mathContext.getRoundingMode());
}

代码示例来源:origin: SeanDragon/protools

/**
 * 开平方
 *
 * @param scale
 *         精度
 *
 * @return 结果
 */
public Decimal sqrt2(int scale) {
  if (this.bigDecimal.divide(new BigDecimal(1), mathContext).doubleValue() == 1.00D || this.bigDecimal.divide(new BigDecimal(2), mathContext).doubleValue() == 1.00D) {
    this.bigDecimal = new BigDecimal(intValue());
  }
  if (scale > 13) {
    this.bigDecimal = ToolDecimal.sqrt(this.bigDecimal, scale, mathContext.getRoundingMode());
  } else {
    double sqrt = Math.sqrt(this.bigDecimal.doubleValue());
    this.bigDecimal = new BigDecimal(sqrt, mathContext);
  }
  return this;
}

代码示例来源:origin: com.google.gwt/gwt-servlet

public static void serialize(SerializationStreamWriter streamWriter,
  MathContext instance) throws SerializationException {
 streamWriter.writeInt(instance.getPrecision());
 streamWriter.writeInt(instance.getRoundingMode().ordinal());
}

代码示例来源:origin: qcadoo/mes

private BigDecimal setScale(final BigDecimal valueOrNull, final int scale, final MathContext mc) {
  if (valueOrNull == null) {
    return null;
  }
  return valueOrNull.setScale(scale, mc.getRoundingMode());
}

代码示例来源:origin: optimatika/ojAlgo

private BigDecimal scale(final BigDecimal number) {
  BigDecimal retVal = number;
  if (myScale > Integer.MIN_VALUE) {
    retVal = retVal.setScale(myScale, myMathContext.getRoundingMode());
  }
  if (retVal.signum() == 0) {
    return BigMath.ZERO;
  } else {
    return retVal.stripTrailingZeros();
  }
}

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

@Override
  public BigDecimal eval(List<BigDecimal> parameters) {
    BigDecimal toRound = parameters.get(0);
    int precision = parameters.get(1).intValue();
    return toRound.setScale(precision, mc.getRoundingMode());
  }
});

代码示例来源:origin: org.apache.felix/org.apache.felix.gogo.runtime

@Override
  public BigDecimal eval(List<BigDecimal> parameters) {
    BigDecimal toRound = parameters.get(0);
    int precision = parameters.get(1).intValue();
    return toRound.setScale(precision, mc.getRoundingMode());
  }
});

代码示例来源:origin: uklimaschewski/EvalEx

@Override
  public BigDecimal eval(List<BigDecimal> parameters) {
    assertNotNull(parameters.get(0), parameters.get(1));
    BigDecimal toRound = parameters.get(0);
    int precision = parameters.get(1).intValue();
    return toRound.setScale(precision, mc.getRoundingMode());
  }
});

代码示例来源:origin: org.ojalgo/ojalgo

public static NumberContext getGeneral(final int precision, final int scale) {
  final NumberFormat tmpFormat = NumberStyle.GENERAL.getFormat();
  final int tmpPrecision = precision;
  final int tmpScale = scale;
  final RoundingMode tmpRoundingMode = DEFAULT_MATH.getRoundingMode();
  return new NumberContext(tmpFormat, tmpPrecision, tmpScale, tmpRoundingMode);
}

代码示例来源:origin: org.ojalgo/ojalgo

/**
 * The scale will be undefined/unlimited.
 */
public static NumberContext getMath(final MathContext context) {
  final NumberFormat tmpFormat = NumberStyle.GENERAL.getFormat();
  final int tmpPrecision = context.getPrecision();
  final int tmpScale = DEFAULT_SCALE;
  final RoundingMode tmpRoundingMode = context.getRoundingMode();
  return new NumberContext(tmpFormat, tmpPrecision, tmpScale, tmpRoundingMode);
}

代码示例来源:origin: org.ojalgo/ojalgo

public static NumberContext getCurrency(final Locale locale) {
  final NumberFormat tmpFormat = NumberStyle.CURRENCY.getFormat(locale);
  final int tmpPrecision = DEFAULT_MATH.getPrecision();
  final int tmpScale = 2;
  final RoundingMode tmpRoundingMode = DEFAULT_MATH.getRoundingMode();
  return new NumberContext(tmpFormat, tmpPrecision, tmpScale, tmpRoundingMode);
}

代码示例来源:origin: espertechinc/esper

public CodegenExpression initCtorScoped() {
  if (mathContext == null) {
    return constantNull();
  }
  return newInstance(MathContext.class, constant(mathContext.getPrecision()),
      enumValue(RoundingMode.class, mathContext.getRoundingMode().name()));
}

相关文章