Here you can find the source of roundAndScale(double startValue, int places)
public static double roundAndScale(double startValue, int places)
//package com.java2s; public class Main { public static double roundAndScale(double startValue, int places) { double multiplier = calculateMultiplier(places); double ourNoughtPointFive = 0.50000000001; double absoluteValue = Math.abs(startValue); double valueToBeFloored = (absoluteValue * multiplier) + ourNoughtPointFive; double roundedValue = Math.floor(valueToBeFloored); double returnValue = roundedValue / multiplier; if (startValue < 0) returnValue = -returnValue;//from www . j a v a 2s . c om return returnValue; } private static double calculateMultiplier(int scale) { double retval = 1; for (int i = 0; i < scale; i++) { retval = retval * 10; } return retval; } }