Java BigDecimal incRatio(BigDecimal o1, BigDecimal o2)

Here you can find the source of incRatio(BigDecimal o1, BigDecimal o2)

Description

calc a increase ratio between two BigDecimal;

License

Open Source License

Parameter

Parameter Description
o1 <code>java.lang.Integer</code>
o2 <code>java.lang.Integer</code>

Return

(o1-o2)/o2

Declaration

public static BigDecimal incRatio(BigDecimal o1, BigDecimal o2) 

Method Source Code


//package com.java2s;
/*/*w w  w.  ja v a 2s .  c o m*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.math.BigDecimal;

public class Main {
    /**
     * calc a ratio increase between two Integer;
     *
     * @param o1 <code>java.lang.Integer</code>
     * @param o2 <code>java.lang.Integer</code>
     * @return (o1-o2)/o2
     */
    public static BigDecimal incRatio(Integer o1, Integer o2) {
        double d1, d2;
        if (o1 == null && o2 == null) {
            return new BigDecimal(0);
        }
        if (o2 == null || o2.intValue() == 0) {
            return new BigDecimal(100);
        }
        if (o1 != null) {
            d1 = o1.doubleValue();
        } else {
            d1 = 0;
        }
        d2 = o2.doubleValue();
        return new BigDecimal((d1 - d2) / d2 * 100);
    }

    /**
     * calc a increase ratio between two BigDecimal;
     *
     * @param o1 <code>java.lang.Integer</code>
     * @param o2 <code>java.lang.Integer</code>
     * @return (o1-o2)/o2
     */
    public static BigDecimal incRatio(BigDecimal o1, BigDecimal o2) {
        double d1, d2;
        if (o1 == null && o2 == null) {
            return new BigDecimal(0);
        }
        if (o2 == null || o2.intValue() == 0) {
            return new BigDecimal(100);
        }
        if (o1 != null) {
            d1 = o1.doubleValue();
        } else {
            d1 = 0;
        }
        d2 = o2.doubleValue();
        return new BigDecimal((d1 - d2) / d2 * 100);
    }
}

Related

  1. getWithoutTrailingZeroes(@Nullable final BigDecimal aValue)
  2. hash(BigDecimal bd)
  3. hasSignedChanged(final BigDecimal v1, final BigDecimal v2)
  4. htmlFooter(String providerNo, int count, BigDecimal total)
  5. humanReadableByteCount(BigDecimal bytes, Boolean si)
  6. intToBigDecimal(int i)
  7. intValue(BigDecimal a)
  8. inverse(final BigDecimal amount)
  9. invert(BigDecimal d)