NumberFormat f = NumberFormat.getInstance(loc); if (f instanceof DecimalFormat) { ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); }
/** * Format a percentage for presentation to the user. * @param done the percentage to format (0.0 to 1.0) * @param digits the number of digits past the decimal point * @return a string representation of the percentage */ public static String formatPercent(double done, int digits) { DecimalFormat percentFormat = new DecimalFormat("0.00%"); double scale = Math.pow(10.0, digits+2); double rounded = Math.floor(done * scale); percentFormat.setDecimalSeparatorAlwaysShown(false); percentFormat.setMinimumFractionDigits(digits); percentFormat.setMaximumFractionDigits(digits); return percentFormat.format(rounded / scale); }
import java.text.DecimalFormat; public class Asdf { public static void main(String[] args) { DecimalFormat format = new DecimalFormat(); format.setDecimalSeparatorAlwaysShown(false); Double asdf = 2.0; Double asdf2 = 2.11; Double asdf3 = 2000.11; System.out.println( format.format(asdf) ); System.out.println( format.format(asdf2) ); System.out.println( format.format(asdf3) ); } }
df.setDecimalSeparatorAlwaysShown(true); dfnd = new DecimalFormat("#,###"); this.et = et;
format.setMinimumIntegerDigits(minIntegerDigits.intValue()); format.setDecimalSeparatorAlwaysShown(decimalPointType != NumberPointType.NONE && fractionDigits.intValue() > 0); format.setGroupingUsed(thousandsPointType != NumberPointType.NONE); format.setDecimalFormatSymbols(computeDecimalFormatSymbols(decimalPointType, thousandsPointType, locale));
/** * Allows you to get the behavior of the decimal separator with integers. */ public void setDecimalSeparatorAlwaysShown(boolean decimalSeparatorAlwaysShown){ format.setDecimalSeparatorAlwaysShown(decimalSeparatorAlwaysShown); }
private static String formatNumber(final double number, boolean commaSep) { DecimalFormat f = new DecimalFormat(commaSep ? "#,###.###" : "###.###"); f.setDecimalSeparatorAlwaysShown(false); return f.format(number); }
private static String formatNumber(final double number, boolean commaSep) { DecimalFormat f = new DecimalFormat(commaSep ? "#,###.###" : "###.###"); f.setDecimalSeparatorAlwaysShown(false); return f.format(number); }
private static String formatNumber(final double number, boolean commaSep) { DecimalFormat f = new DecimalFormat(commaSep ? "#,###.###" : "###.###"); f.setDecimalSeparatorAlwaysShown(false); return f.format(number); }
public String getFileSizeKBFormat() { String fileSizeKBStr = ""; if (fileSize != null) { double fileSizeKB = fileSize.doubleValue() / 1000; DecimalFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setDecimalSeparatorAlwaysShown(true); fileSizeKBStr = nf.format(fileSizeKB); } return fileSizeKBStr; }
public String getFileSizeKBFormat() { String fileSizeKBStr = ""; if (fileSize != null) { double fileSizeKB = fileSize.doubleValue() / 1000; DecimalFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setDecimalSeparatorAlwaysShown(true); fileSizeKBStr = nf.format(fileSizeKB); } return fileSizeKBStr; }
public static final String objectToString(Object obj, DecimalFormat fmt) { fmt.setDecimalSeparatorAlwaysShown(false); if(obj instanceof Double) return fmt.format(((Double)obj).doubleValue()); if(obj instanceof Long) return fmt.format(((Long)obj).longValue()); else return obj.toString(); }
BigDecimal a = new BigDecimal("4.3000"); BigDecimal b = new BigDecimal("4.0"); DecimalFormat f = new DecimalFormat("#.#"); f.setDecimalSeparatorAlwaysShown(false) f.setMaximumFractionDigits(340); System.out.println(f.format(a)); System.out.println(f.format(b));
BigDecimal decimal = new BigDecimal("100.25"); BigDecimal decimal2 = new BigDecimal("1000.70"); BigDecimal decimal3 = new BigDecimal("10000.00"); DecimalFormat format = new DecimalFormat("###,###,###,###,###.##"); format.setDecimalSeparatorAlwaysShown(true); format.setMinimumFractionDigits(2); System.out.println(format.format(decimal)); System.out.println(format.format(decimal2)); System.out.println(format.format(decimal3));
public static String bigDecimal2String(BigDecimal value) { DecimalFormat format = new DecimalFormat("0.##"); DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); symbols.setDecimalSeparator('.'); format.setDecimalFormatSymbols(symbols); format.setDecimalSeparatorAlwaysShown(false); return format.format(value); }
private static String format(final long value, final long divider, final String unit) { final double result = divider > 1 ? (double) value / (double) divider : (double) value; DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); decimalFormat.setMinimumFractionDigits(0); decimalFormat.setGroupingUsed(false); decimalFormat.setDecimalSeparatorAlwaysShown(false); return decimalFormat.format(result) + " " + unit; }
public WmsUrlBuilder(RenderedTile tile, VectorLayer layer, String layerName) { this.tile = tile; this.layer = layer; this.layerName = layerName; decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setGroupingUsed(false); decimalFormat.setMinimumFractionDigits(0); decimalFormat.setMaximumFractionDigits(100); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); decimalFormat.setDecimalFormatSymbols(symbols); }
DoubleFormatter(String pattern) { final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); format = new DecimalFormat(pattern, decimalFormatSymbols); format.setParseIntegerOnly(false); format.setParseBigDecimal(false); format.setDecimalSeparatorAlwaysShown(true); }
DoubleFormatter(String pattern) { final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); format = new DecimalFormat(pattern, decimalFormatSymbols); format.setParseIntegerOnly(false); format.setParseBigDecimal(false); format.setDecimalSeparatorAlwaysShown(true); }
DoubleFormatter(String pattern) { final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); format = new DecimalFormat(pattern, decimalFormatSymbols); format.setParseIntegerOnly(false); format.setParseBigDecimal(false); format.setDecimalSeparatorAlwaysShown(true); }