Java Number Round roundByte(final double value)

Here you can find the source of roundByte(final double value)

Description

Rounds a float value and clamp the result between 0 and 255 inclusive.

License

Open Source License

Declaration

public static int roundByte(final double value) 

Method Source Code

//package com.java2s;
/*//  w ww.j a  v  a2  s .  c om
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 * 
 *    (C) 2001-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

public class Main {
    /**
     * Rounds a float value and clamp the result between 0 and 255 inclusive.
     */
    public static int roundByte(final double value) {
        return (int) Math.min(Math.max(Math.round(value), 0), 255);
    }
}

Related

  1. round_pow2(int x)
  2. round_up(int value, int multiple)
  3. roundAdd(double a, double b)
  4. roundAndCrop(final float x, final int min, final int max)
  5. roundByGridSize(int value)
  6. roundBytesToGB(long bytes)
  7. roundBytesUpToWords(int bytes)
  8. roundChipRewardDown(long chips)
  9. roundCss(double v, int n)