waterml/src/main/java/ucar/nc2/ogc/erddap/util/ErddapMath2.java
public static int roundToInt(double d) {
        return d > Integer.MAX_VALUE || d <= Integer.MIN_VALUE - 0.5 || !isFinite(d)? 
            Integer.MAX_VALUE : 
            (int)Math.round(d); //safe since checked for larger values above
    }
public static int roundToInt(double d) {
        return d > Integer.MAX_VALUE || d <= Integer.MIN_VALUE - 0.5 || !isFinite(d)? 
            Integer.MAX_VALUE : 
            (int)Math.round(d); //safe since checked for larger values above
    }
Safely rounds a double to an int.
(Math.round but rounds to a long and not safely.)

@param d any double
@return Integer.MAX_VALUE if d is too small, too big, or NaN;
otherwise d, rounded to the nearest int.
Undesirable: d.5 rounds up for positive numbers, down for negative.