Here you can find the source of FormatNumber(Object o,String patter)
public static String FormatNumber(Object o,String patter)
//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; } }