Java tutorial
//package com.java2s; /* See http://variableinc.com/terms-use-license for the full license governing this code. */ public class Main { private static final int COLOR_FLOAT_TO_INT_FACTOR = 255; private static int normalizeDouble(double f) { double f2 = Math.max(0.0, Math.min(1.0, f)); return (int) Math.floor(f2 == 1.0 ? COLOR_FLOAT_TO_INT_FACTOR : f2 * (COLOR_FLOAT_TO_INT_FACTOR + 1)); } }