Java examples for java.lang:double Format
Format number to given decimal places (to)
//package com.java2s; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; public class Main { /**//from www . j a v a 2s .c o m * Format number to given decimal places (to) * * @param value the value * @param maxDecimals the decimals to * @return the string */ public static String formatNumberDecimalMax(Number value, int maxDecimals) { DecimalFormat df = new DecimalFormat("0.00", new DecimalFormatSymbols(new Locale("nl", "BE"))); df.setMinimumFractionDigits(0); df.setMaximumFractionDigits(maxDecimals); return df.format(value); } }