Here you can find the source of getPercent(Double value)
public static String getPercent(Double value)
//package com.java2s; /******************************************************************************* * @FileName: helper.java 2013-7-12 ????4:13:15 * @Author: zhangzhia/*ww w . j av a 2s . c o m*/ * @Copyright: 2013 YUTONG Group CLW. All rights reserved. * @Remarks: YUTONG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *******************************************************************************/ import java.text.DecimalFormat; public class Main { public static String getPercent(Double value) { if (value != null && value > 0) { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(1); df.setMinimumFractionDigits(1); if (1 == value) { return "100%"; } else { return df.format(value * 100) + "%"; } } else { return "--"; } } }