Java BigDecimal Format formatPercentDecimalDouble(Object input)

Here you can find the source of formatPercentDecimalDouble(Object input)

Description

format Percent Decimal Double

License

Open Source License

Declaration

public static Double formatPercentDecimalDouble(Object input) 

Method Source Code


//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.math.BigDecimal;

public class Main {
    public static Double formatPercentDecimalDouble(Object input) {
        if (checkInput(input)) {
            BigDecimal bd1 = new BigDecimal(input.toString());
            BigDecimal bd2 = new BigDecimal("100"); //$NON-NLS-1$
            return bd1.multiply(bd2).doubleValue();
        }/*w ww  .j a v a  2 s. c  o  m*/
        return null;
    }

    /**
     * DOC Zqin Comment method "checkInput".
     * 
     * @param input the object that was formated.
     * @return true if the input is valid, else false;
     */
    private static boolean checkInput(Object input) {
        if (input == null || "".equals(input)) { //$NON-NLS-1$
            return false;
        } else {
            Double db = new Double(input.toString());
            if (db.equals(Double.NaN)) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. formatNumberStr(String numberStr, Integer scale)
  2. formatNumer(BigDecimal value, int decimalPlaces, Locale locale, boolean roundCommercial)
  3. formatoDecimal(String tipo, BigDecimal valor)
  4. formatPercent(BigDecimal percent)
  5. formatPercentage(BigDecimal percentage)
  6. formatQuantity(BigDecimal quantity)
  7. formatQuantity(BigDecimal quantity)
  8. formatRate(BigDecimal rate)
  9. formatRateForDisplay(BigDecimal rate)