Here you can find the source of decimalFormat(double no)
public static String decimalFormat(double no)
//package com.java2s; import java.text.DecimalFormat; public class Main { public static String decimalFormat(double no) { DecimalFormat df = new DecimalFormat("######.##"); String val = df.format(no); int index = val.indexOf("."); if (index == -1) val = val + ".00"; else {//from www . j a v a2 s .c o m if (val.substring(index + 1, val.length()).length() - 1 == 0) val = val + "0"; } return val; } }