Java examples for java.lang:Math Value
Forces a numerical value to be between a min and a max.
//package com.java2s; public class Main { /**/* w w w .j a va 2s. co m*/ * Forces a numerical value to be between a min * and a max. * * @param min If less than min, returns min * @param max If greater than max, returns max * @param value Value to test * @return Coerced value */ public static double coerce(double min, double max, double value) { return (value > max) ? max : (value < min) ? min : value; } }