org.apache.commons.math3.util.Precision.round()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(123)

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

Precision.round介绍

[英]Rounds the given value to the specified number of decimal places. The value is rounded using the BigDecimal#ROUND_HALF_UP method.
[中]将给定值舍入到指定的小数位数。使用BigDecimal#四舍五入(HALF)向上方法对值进行四舍五入。

代码示例

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Rounds the given value to the specified number of decimal places.
 * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
 *
 * @param x Value to round.
 * @param scale Number of digits to the right of the decimal point.
 * @return the rounded value.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
public static float round(float x, int scale) {
  return round(x, scale, BigDecimal.ROUND_HALF_UP);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Rounds the given value to the specified number of decimal places.
 * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
 *
 * @param x Value to round.
 * @param scale Number of digits to the right of the decimal point.
 * @return the rounded value.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
public static double round(double x, int scale) {
  return round(x, scale, BigDecimal.ROUND_HALF_UP);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
   * {@inheritDoc}
   */
  @Override
  public String toString() {
    return String.format(
        "index=%.0f,n=%.0f,np=%.2f,q=%.2f,dn=%.2f,prev=%d,next=%d",
        (double) index, Precision.round(intMarkerPosition, 0),
        Precision.round(desiredMarkerPosition, 2),
        Precision.round(markerHeight, 2),
        Precision.round(desiredMarkerIncrement, 2), previous.index,
        next.index);
  }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * Rounds the given value to the specified number of decimal places.
 * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
 *
 * @param x Value to round.
 * @param scale Number of digits to the right of the decimal point.
 * @return the rounded value.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
public static float round(float x, int scale) {
  return round(x, scale, BigDecimal.ROUND_HALF_UP);
}

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

/**
 * Rounds the given value to the specified number of decimal places.
 * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
 *
 * @param x Value to round.
 * @param scale Number of digits to the right of the decimal point.
 * @return the rounded value.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
public static double round(double x, int scale) {
  return round(x, scale, BigDecimal.ROUND_HALF_UP);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * Rounds the given value to the specified number of decimal places.
 * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
 *
 * @param x Value to round.
 * @param scale Number of digits to the right of the decimal point.
 * @return the rounded value.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
public static double round(double x, int scale) {
  return round(x, scale, BigDecimal.ROUND_HALF_UP);
}

代码示例来源:origin: meyerjp3/psychometrics

public Double checkConstraints(Double value){
  if(value<minPossibleScore){
    return Precision.round(minPossibleScore, precision);
  }else if(value>maxPossibleScore){
    return Precision.round(maxPossibleScore, precision);
  }else{
    return Precision.round(value, precision);
  }
}

代码示例来源:origin: meyerjp3/psychometrics

public double getIntercept(){
  return Precision.round(intercept, precision);
}

代码示例来源:origin: meyerjp3/psychometrics

public Double checkPrecisionOnly(Double value){
  return Precision.round(value, precision);
}

代码示例来源:origin: meyerjp3/psychometrics

public double getScale(){
  return Precision.round(slope, precision);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
   * {@inheritDoc}
   */
  @Override
  public String toString() {
    return String.format(
        "index=%.0f,n=%.0f,np=%.2f,q=%.2f,dn=%.2f,prev=%d,next=%d",
        (double) index, Precision.round(intMarkerPosition, 0),
        Precision.round(desiredMarkerPosition, 2),
        Precision.round(markerHeight, 2),
        Precision.round(desiredMarkerIncrement, 2), previous.index,
        next.index);
  }
}

代码示例来源:origin: everwatchsolutions/json-data-generator

@Override
public Double getNextRandomValue() {
  double range = max - min;
  double scaled = rand.nextDouble() * range;
  double shifted = scaled + min;
  return Precision.round(shifted, decimalPlaces);
}

代码示例来源:origin: sakaiproject/sakai

public static String getRoundedGrade(Double theGrade, Double points) throws Exception {
  if (theGrade < 0.0 || theGrade > 1.0) {
    throw new Exception("Grade out of range");
  }
  theGrade = theGrade * points;
  theGrade = Precision.round(theGrade, 2);
  return String.valueOf(theGrade);
}

代码示例来源:origin: org.sakaiproject.basiclti/basiclti-common

public static String getRoundedGrade(Double theGrade, Double points) throws Exception {
  if ( theGrade < 0.0 || theGrade > 1.0 ) {
    throw new Exception("Grade out of range");
  }
  theGrade = theGrade * points;
  theGrade = Precision.round(theGrade,2);
  return String.valueOf(theGrade);
}

代码示例来源:origin: dhis2/dhis2-core

private static String parseCoordinate( String number, int precision, NumberFormat nf )
    throws ParseException
  {
    return Double.toString( Precision.round(nf.parse(number).doubleValue(), precision ) );
  }
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
 public Object doWork(Object value, Object value2) {
  if(null == value){
   return null;
  }
  else if(value instanceof List){
   return ((List<?>)value).stream().map(innerValue -> doWork(innerValue, ((Number)value2).intValue())).collect(Collectors.toList());
  }
  else{
   return Precision.round(((Number)value).doubleValue(), ((Number)value2).intValue());
  }
 }
}

代码示例来源:origin: meyerjp3/psychometrics

public void addDoubleAt(int index, double number){
  if(index<numberOfColumns){
    String s = String.format(colFormats[index].getFormat(), Precision.round(number, colFormats[index].getPrecision()));
    if(columnPadding>0) s += String.format("%" + columnPadding + "s", "");
    cellText[index] = s;
  }
}

代码示例来源:origin: org.visallo/visallo-core

private void applyDoubleEqualityToQuery(Query graphQuery, JSONObject obj, Object value0) throws ParseException {
  String propertyName = obj.getString("propertyName");
  JSONObject metadata = obj.has("metadata") ? obj.getJSONObject("metadata") : null;
  if (metadata != null && metadata.has("http://visallo.org#inputPrecision") && value0 instanceof Double) {
    double doubleParam = (double) value0;
    int inputPrecision = Math.max(metadata.getInt("http://visallo.org#inputPrecision"), 0);
    double lowerBound = Precision.round(doubleParam, inputPrecision, BigDecimal.ROUND_DOWN);
    double upperBound = Precision.equals(doubleParam, lowerBound, Precision.EPSILON) ? lowerBound + Math.pow(10, -inputPrecision) :
        Precision.round(doubleParam, inputPrecision, BigDecimal.ROUND_UP);
    graphQuery.has(propertyName, Compare.GREATER_THAN_EQUAL, (lowerBound - Precision.EPSILON));
    graphQuery.has(propertyName, Compare.LESS_THAN, (upperBound + Precision.EPSILON));
  } else {
    graphQuery.has(propertyName, Compare.EQUAL, value0);
  }
}

代码示例来源:origin: meyerjp3/psychometrics

/**
 * A linear transformation can be applied to teh score table. This method should be called after
 * {@link #computePersonStandardErrors()}.
 *
 * @param lt linear transformation to be applied.
 * @param precision number of decimal places to retain after the linear transformation.
 */
public void linearTransformation(DefaultLinearTransformation lt, int precision){
  for(int i=0;i<theta.length;i++){
    theta[i] = Precision.round(lt.transform(theta[i]), precision);
    thetaStdError[i] *= lt.getScale();
  }
}

代码示例来源:origin: us.ihmc/ihmc-path-planning-test

@ContinuousIntegrationTest(estimatedDuration = 0.0)
  @Test(timeout = 30000)
  public void testRound() throws Exception
  {
   Random random = new Random(43566787);

   for (int i = 0; i < ITERATIONS; i++)
   {
     double raw = EuclidCoreRandomTools.nextDouble(random, 1000.0);
     double expected = Precision.round(raw, 4);
     double actual = ConnectionPoint3D.round(raw);
     assertEquals(expected, actual, EPSILON);
   }
  }
}

相关文章