Here you can find the source of roundedApply(double value, double percent, double delta)
Parameter | Description |
---|---|
value | the value to apply everything |
percent | the percentage to be applied |
delta | the delta for the last rounding process |
public static double roundedApply(double value, double percent, double delta)
//package com.java2s; /* // w w w. j av a 2 s . c o m * Copyright (C) 2014 GG-Net GmbH - Oliver G?nther * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Applies the value with percent and rounds the result if its in space of the delta. * <p>The value and percent are applied as follows: value * (1+percent). * If abs(round(result) - result) < delta return round(result) else result * </p> * <p/> * @param value the value to apply everything * @param percent the percentage to be applied * @param delta the delta for the last rounding process * @return the correct or rounded result. */ public static double roundedApply(double value, double percent, double delta) { double correct = Math.round(value * (1 + percent) * 100.0) / 100.0; double rounded = Math.round(correct); if (Math.abs(rounded - correct) < delta) return rounded; return correct; } }