Here you can find the source of percent(double p1, double p2)
public static String percent(double p1, double p2)
//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; } }