Java Number Format Pattern FormatNumber(Object o,String patter)

Here you can find the source of FormatNumber(Object o,String patter)

Description

Format Number

License

Apache License

Declaration

public static String FormatNumber(Object o,String patter)
  

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    public static String FormatNumber(Object o, String patter) {
        double d = 0;
        try {/*  w  w w  .  jav  a2s. c o m*/
            d = Double.parseDouble(String.valueOf(o));
            DecimalFormat df = new DecimalFormat(patter);
            return df.format(d);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return "";
        }
    }

    public static String FormatNumber(String s) {
        double d = 0;
        try {
            d = Double.parseDouble(s);
            DecimalFormat df = new DecimalFormat(",###.00");
            return df.format(d);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return "";
        }
    }

    public static double parseDouble(String param) {
        double l = 0;
        try {
            l = Double.parseDouble(param);
        } catch (Exception e) {
        }

        return l;
    }
}

Related

  1. formatNumber(int source)
  2. formatNumber(long number)
  3. formatNumber(long number)
  4. formatNumber(Number num)
  5. formatNumber(Number number)
  6. formatoDecimalPunto(String numero)
  7. formatQuantity(Long quantity)
  8. formattedDuration(long pStartTime)
  9. formatThousands(String inValue)