Java Number Percentage Format getPercent(Double value)

Here you can find the source of getPercent(Double value)

Description

get Percent

License

Open Source License

Declaration

public static String getPercent(Double value) 

Method Source Code

//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 "--";
        }
    }
}

Related

  1. getPercent(Double num)
  2. getPercent(double percent)
  3. getPercent(final long downloadCurrent, final long downloadMax)
  4. getPercent(long l1, long l2)
  5. getPercent(long val1, long val2)
  6. getPercentFormatter()