Here you can find the source of getPercentage(double number)
public static String getPercentage(double number)
//package com.java2s; import java.text.NumberFormat; public class Main { public static String getPercentage(double number) { NumberFormat nf = NumberFormat.getPercentInstance(); nf.setMaximumFractionDigits(2);//from www . jav a 2 s. c o m nf.setMinimumFractionDigits(2); return nf.format(number); } public static String format(double number) { if (number == (int) number) return String.valueOf((int) number); else return String.valueOf(number); } }