Here you can find the source of clampRoundByte(float in)
public static final byte clampRoundByte(float in)
//package com.java2s; /*//from www .java 2 s . c o m * $RCSfile: ImageUtil.java,v $ * * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.2 $ * $Date: 2006/07/21 20:53:28 $ * $State: Exp $ */ public class Main { /** * Clamps and rounds a number to the range supported by * byte data type. The input number is float. */ public static final byte clampRoundByte(float in) { return (in > 0xFF ? (byte) 0xFF : (in >= 0 ? (byte) (in + 0.5F) : (byte) 0)); } /** * Clamps and rounds a number to the range supported by * byte data type. The input number is double. */ public static final byte clampRoundByte(double in) { return (in > 0xFF ? (byte) 0xFF : (in >= 0 ? (byte) (in + 0.5) : (byte) 0)); } }