Java Number Round roundedApply(double value, double percent, double delta)

Here you can find the source of roundedApply(double value, double percent, double delta)

Description

Applies the value with percent and rounds the result if its in space of the delta.

License

Open Source License

Parameter

Parameter Description
value the value to apply everything
percent the percentage to be applied
delta the delta for the last rounding process

Return

the correct or rounded result.

Declaration

public static double roundedApply(double value, double percent, double delta) 

Method Source Code

//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) &lt; 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;
    }
}

Related

  1. roundChipRewardDown(long chips)
  2. roundCss(double v, int n)
  3. rounded(double value, int places, int ceilOrFloor)
  4. ROUNDED_DIV(long a, long b)
  5. rounded_shift_down(long x, int n)
  6. roundedDollarValue(double d)
  7. roundedLog(double value, double exponent)
  8. roundedLog10(int n)
  9. roundedSatisfaction(double value)