Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * This used when a double ends in 0 (IE 100.0) and you want to remove the significant figures * after the decimal point (assuming they end in zero) * @param value The double to convert * @param addDollarSign boolean, if null passed, nothing, if true passed, will add * a $ to the beginning * @return A String, formatted correctly. Will look like this: 104.44 or $99. * if the last 2 are 00, it will remove the significant figures after * the decimal as well as the decimal itself */ public static String convertDoubleToStringAddZero(double value, Boolean addDollarSign) { String str = Double.toString(value); if (str == null) { return null; } //String ending = str.substring((str.length()-2)); String ending = str.substring((str.length() - 2), (str.length() - 1)); if (ending.equalsIgnoreCase(".")) { str = str + "0"; } if (addDollarSign != null) { if (addDollarSign) { str = "$" + str; } } ending = str.substring((str.length() - 3)); if (ending.equalsIgnoreCase(".00")) { str = str.replace(".00", ""); } return str; } }