Java Percentage Format getRoundPercent(double f)

Here you can find the source of getRoundPercent(double f)

Description

get Round Percent

License

Open Source License

Declaration

public static String getRoundPercent(double f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {

    public static String getRoundPercent(double f) {
        DecimalFormat df = new DecimalFormat("#####.00");

        return df.format(f);
    }//from w  w  w  . j  a v  a 2  s. c  om

    public static int getRoundPercent(float f) {
        double r = f * 100;
        String round = String.valueOf(r);
        if (round.indexOf(".") > 0) {
            round = round.substring(0, round.indexOf("."));
            int intValue = Integer.parseInt(round);
            if (r - intValue >= 0.5)
                intValue += 1;
            round = String.valueOf(intValue);
        }
        return Integer.parseInt(round);
    }
}

Related

  1. getPercentage(double number, int fractionDigits)
  2. getPercentage(int numerator, int denominator)
  3. getPercentage(long duration, long lapso)
  4. getPercentage(long numerator, long denominator)
  5. getPercentageString(double percent)
  6. numberToPercent2Scale(Double number)
  7. percent(double number)
  8. percent(double p1, double p2)
  9. percentage(Double v, String postfix)