Java Percentage Format percentTotal(double value, double total)

Here you can find the source of percentTotal(double value, double total)

Description

percent Total

License

Open Source License

Declaration

public static String percentTotal(double value, double total) 

Method Source Code

//package com.java2s;
/**/* w  w  w  .j  a v a 2  s  . c  om*/
 *  Colloid project
 *
 *  Combat log analyzer.
 *
 *  copyright: (c) 2013 by Darek <netmik12 [AT] gmail [DOT] com>
 *  license: BSD, see LICENSE for more details
 */

import java.text.DecimalFormat;

public class Main {
    public static String percentTotal(double value, double total) {
        if (total <= 0) {
            return "0%";
        }
        final DecimalFormat df = new DecimalFormat("#.00");
        double result = (value * 100) / total;
        if (result > 0.01) {
            return df.format(result);
        }

        return "0.00";
    }
}

Related

  1. percentFormat(BigDecimal interestRate)
  2. percentFormat(final BigDecimal bd)
  3. percentFormat(final double value)
  4. percentFormat(float value)
  5. percentFormat(Object object)
  6. roundedPercentageGreaterThan(double left, double right)
  7. toPercent(Double doubleValue)
  8. toPercent(double percent)
  9. toPercent(double value)