Java Number Round roundIfClose(double val)

Here you can find the source of roundIfClose(double val)

Description

Local function to round "sufficiently close" Number values to whole numbers, to prevent unnecessary aliasing in drawing shapes.

License

Open Source License

Parameter

Parameter Description
val a parameter

Declaration

protected static double roundIfClose(double val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  ww .  j av  a2  s  . c om
     * Local function to round "sufficiently close" Number values to whole
     * numbers, to prevent unnecessary aliasing in drawing shapes.
     *
     * @param val
     * @return
     */
    protected static double roundIfClose(double val) {
        double nVal = Math.round(val);
        if (Math.abs(val - nVal) < 0.001) {
            return nVal;
        } else {
            return val;
        }
    }
}

Related

  1. roundFloatToUnitInverse(final float graphValue, final float graphUnit)
  2. roundFormat(final int numPrec, final double number)
  3. RoundFullUp(double d)
  4. roundHalfAway(double d)
  5. RoundHalfUp(double d)
  6. Rounding(double d, int i)
  7. rounding(double val)
  8. roundingRightShift(int x, int count)
  9. roundIntegerToNearestUpperTenth(int a)