Here you can find the source of rangeToScale(long rawValue, long rangeMin, long rangeMax, double scaleMin, double scaleMax)
public static double rangeToScale(long rawValue, long rangeMin, long rangeMax, double scaleMin, double scaleMax)
//package com.java2s; /*/*from w w w . j ava 2 s . co m*/ * Copyright (c) 2014 aleon GmbH. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Markus Rathgeb - initial API and implementation and/or initial documentation */ public class Main { public static double rangeToScale(long rawValue, long rangeMin, long rangeMax, double scaleMin, double scaleMax) { final double multiplier = (scaleMax - scaleMin) / (rangeMax - rangeMin); final double devValue = multiplier * (rawValue - rangeMin) + scaleMin; return fitInRange(devValue, scaleMin, scaleMax); } public static <T extends Comparable<T>> T fitInRange(T value, T min, T max) { if (value.compareTo(min) < 0) { return min; } else if (value.compareTo(max) > 0) { return max; } else { return value; } } }