/** * 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); }
/** * 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); }
/** * {@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); } }
/** * 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); }
/** * 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); }
/** * 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); }
public double getIntercept(){ return Precision.round(intercept, precision); }
public Double checkPrecisionOnly(Double value){ return Precision.round(value, precision); }
public double getScale(){ return Precision.round(slope, precision); }
/** * {@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); } }
@Override public Double getNextRandomValue() { double range = max - min; double scaled = rand.nextDouble() * range; double shifted = scaled + min; return Precision.round(shifted, decimalPlaces); }
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); }
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); }
private static String parseCoordinate( String number, int precision, NumberFormat nf ) throws ParseException { return Double.toString( Precision.round(nf.parse(number).doubleValue(), precision ) ); } }
@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()); } } }
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; } }
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); } }
/** * 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(); } }
@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); } } }