Checks if a given double is close to being zero. - Java java.lang

Java examples for java.lang:double

Description

Checks if a given double is close to being zero.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double d = 2.45678;
        System.out.println(almostZero(d));
    }//from   w ww.j  a va  2s  . c o  m

    public static final double ALMOST_ZERO = 0.00001;

    /**
     * Checks if a given double is close to being zero.
     * @param d
     * @return
     */
    public static final boolean almostZero(double d) {
        return Math.abs(d) <= ALMOST_ZERO;
    }
}

Related Tutorials