Here you can find the source of getPercentage(int numerator, int denominator)
public static String getPercentage(int numerator, int denominator)
//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) + "%"; } }