Java Fraction Format formatNumber(double pValue)

Here you can find the source of formatNumber(double pValue)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(double pValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatNumber(double pValue) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                ",##0.00");
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }//from w  w  w. j a  v  a2  s  .  co m

    public static String formatNumber(double pValue, int pDecimales) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                ",##0." + caracterIzquierda("", pDecimales, "0"));
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }

    public static String formatNumber(double pValue, String pFormatNumber) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                pFormatNumber);
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }

    public static String caracterIzquierda(int parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(long parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(double parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(String parmString, int parmLen,
            String parmCaracter) {

        String tempString = parmString;

        if (tempString.length() > parmLen)
            tempString = tempString.substring(
                    tempString.length() - parmLen, tempString.length());
        else {
            while (tempString.length() < parmLen)
                tempString = parmCaracter + tempString;
        }

        return tempString;

    }
}

Related

  1. formatNumber(double number, int decimal)
  2. formatNumber(double number, int val)
  3. formatNumber(Double number, String pattern)
  4. formatNumber(Double numberToFormat, int decimalPlacement)
  5. formatNumber(double paramDouble, int paramInt)
  6. formatNumber(double value)
  7. formatNumber(double value, double epsilon)
  8. formatNumber(final double number)
  9. formatNumber(Float d, int scalar)