Java Percentage Format percent(double p1, double p2)

Here you can find the source of percent(double p1, double p2)

Description

percent

License

Open Source License

Declaration

public static String percent(double p1, double p2) 

Method Source Code


//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String percent(double p1, double p2) {
        String str;//from  w  w  w .  java2  s.  co  m
        if (p1 == 0.0) {
            return "0.00";
        }
        double p3 = p1 / p2;
        DecimalFormat df1 = new DecimalFormat(".00");
        if (p3 * 100 < 1) {
            df1 = new DecimalFormat("0.00");
        }
        str = df1.format(p3 * 100);
        return str;
    }
}

Related

  1. getPercentage(long numerator, long denominator)
  2. getPercentageString(double percent)
  3. getRoundPercent(double f)
  4. numberToPercent2Scale(Double number)
  5. percent(double number)
  6. percentage(Double v, String postfix)
  7. percentage(float f)
  8. percentageAsString(double input)
  9. percentageFormat(BigDecimal value)