Java Percentage Format getPercentage(int numerator, int denominator)

Here you can find the source of getPercentage(int numerator, int denominator)

Description

get Percentage

License

Apache License

Declaration

public static String getPercentage(int numerator, int denominator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;

public class Main {

    public static String getPercentage(int numerator, int denominator) {
        return getPercentage(numerator * 1.00, denominator * 1.00);
    }//w  ww. j  a  v a2  s .  c o  m

    public static String getPercentage(double numerator, double denominator) {
        double percentage = numerator * 1.00 / denominator;
        if (String.valueOf(percentage).endsWith(String.valueOf(Double.NaN))) {
            return "";
        }
        percentage = percentage * 100;
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        return nf.format(percentage) + "%";
    }
}

Related

  1. formatTimePercent(long part, long tot)
  2. getIntRoundPercent(double f)
  3. getOneDecimalPercentFromDouble(double inValue)
  4. getPercentage(double number)
  5. getPercentage(double number, int fractionDigits)
  6. getPercentage(long duration, long lapso)
  7. getPercentage(long numerator, long denominator)
  8. getPercentageString(double percent)
  9. getRoundPercent(double f)