Here you can find the source of formatPercent(double percent)
Parameter | Description |
---|---|
percent | as a decimal value where 1 is 100% |
public static String formatPercent(double percent)
//package com.java2s; //License from project: Apache License import java.text.NumberFormat; public class Main { /**//from w w w .j a v a2 s.co m * Format a number as a percent in the current locale. * The expected number is a decimal value where 1 = 100%, 0.5 = 50%, 1.5 = 150% etc... * * * @param percent as a decimal value where 1 is 100% * @return A string representing the percentage in the current locale */ public static String formatPercent(double percent) { NumberFormat percentFormat = NumberFormat.getPercentInstance(); return percentFormat.format(percent); } public static String formatPercent(double percent, int maximumFractionDigits) { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(maximumFractionDigits); return percentFormat.format(percent); } }