Here you can find the source of roundDecimal(Object value)
public static String roundDecimal(Object value)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { public static String roundDecimal(Object value) { return roundDecimal(value, "###,###.##"); }/* w w w .j a va2 s .c o m*/ public static String roundDecimal(Object value, String pattern) { String res = null; if (pattern == null || pattern.trim().equals("")) pattern = "###,###.##"; DecimalFormat df = new DecimalFormat(pattern); try { if (value instanceof String) { res = df.format(new Double(value.toString())); } else { res = df.format(value); } } catch (IllegalArgumentException e) { e.printStackTrace(); } return res; } public static String roundDecimal(double fTemp) { DecimalFormat df = new DecimalFormat("#.##"); return df.format(fTemp); } public static String roundDecimal(float fTemp) { return roundDecimal((double) fTemp); } public static String roundDecimal(double fTemp, int pos) { DecimalFormat df = new DecimalFormat("#.################"); df.setMaximumFractionDigits(pos); return df.format(fTemp); } }