DecimalFormat formatter = (DecimalFormat)NumberFormat.getCurrencyInstance(); String symbol = formatter.getCurrency().getSymbol(); formatter.setNegativePrefix(symbol+"-"); // or "-"+symbol if that's what you need formatter.setNegativeSuffix("");
if (useParensForNegativeNumbers != 0) { DecimalFormat dformat = (DecimalFormat)format; dformat.setNegativePrefix("("); dformat.setNegativeSuffix(")"); } else { DecimalFormat dformat = (DecimalFormat)format; dformat.setNegativePrefix( "" + dformat.getDecimalFormatSymbols().getMinusSign()); dformat.setNegativeSuffix("");
if (useParensForNegativeNumbers != 0) { DecimalFormat dformat = (DecimalFormat)format; dformat.setNegativePrefix("("); dformat.setNegativeSuffix( "" + dformat.getDecimalFormatSymbols().getPercent() + ")"); } else { DecimalFormat dformat = (DecimalFormat)format; dformat.setNegativePrefix( "" + dformat.getDecimalFormatSymbols().getMinusSign()); dformat.setNegativeSuffix(
/** * Sets the negative prefix. * * <p>Examples: -123, ($123) (with negative suffix), sFr-123 * @param newValue the prefix * @stable ICU 2.0 */ public void setNegativePrefix(String newValue) { ((java.text.DecimalFormat)numberFormat).setNegativePrefix(newValue); }
/** * Sets the negative prefix. * * <p>Examples: -123, ($123) (with negative suffix), sFr-123 * @param newValue the prefix * @stable ICU 2.0 */ public void setNegativePrefix(String newValue) { ((java.text.DecimalFormat)numberFormat).setNegativePrefix(newValue); }
DecimalFormat df = new DecimalFormat("#,##0.0"); df.setRoundingMode(RoundingMode.HALF_UP); df.setNegativePrefix(""); // set negative prefix BLANK String formattedValue = df.format(-0.023); df.setNegativePrefix("-"); // set back to - again System.out.println(formattedValue);
DecimalFormat f = new DecimalFormat(":00"); f.setNegativePrefix(":"); System.out.println(f.format(1)); // :01 System.out.println(f.format(-1)); // :01
DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance(); fmt.setGroupingUsed(true); fmt.setPositivePrefix("Rs. "); fmt.setNegativePrefix("Rs. -"); fmt.setMinimumFractionDigits(2); fmt.setMaximumFractionDigits(2); fmt.format(30382.50);
public static String moneyFormatter(double d){ DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance(); Locale locale = Locale.getDefault(); String symbol = Currency.getInstance(locale).getSymbol(locale); fmt.setGroupingUsed(true); fmt.setPositivePrefix(symbol + " "); fmt.setNegativePrefix("-" + symbol + " "); fmt.setMinimumFractionDigits(2); fmt.setMaximumFractionDigits(2); return fmt.format(d); }
/** * Returns a string representation of this equation system. * * @param prefix the prefix of each line * @param fractionDigits the number of fraction digits for output accuracy * @return a string representation of this equation system */ public String equationsToString(String prefix, int fractionDigits) { DecimalFormat nf = new DecimalFormat(); nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); nf.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); nf.setNegativePrefix(""); nf.setPositivePrefix(""); return equationsToString(prefix, nf); }
/** * Returns a string representation of this equation system. * * @param prefix the prefix of each line * @param fractionDigits the number of fraction digits for output accuracy * @return a string representation of this equation system */ public String equationsToString(String prefix, int fractionDigits) { DecimalFormat nf = new DecimalFormat(); nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); nf.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); nf.setNegativePrefix(""); nf.setPositivePrefix(""); return equationsToString(prefix, nf); }
public FloatingPointFormat( int w, int d ) { width = w; decimal = d; nf = new DecimalFormat( pattern(w, d) ); nf.setPositivePrefix(" "); nf.setNegativePrefix("-"); }
/** * Returns a string representation of this equation system. * * @param prefix the prefix of each line * @param fractionDigits the number of fraction digits for output accuracy * @return a string representation of this equation system */ public String equationsToString(String prefix, int fractionDigits) { DecimalFormat nf = new DecimalFormat(); nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); nf.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); nf.setNegativePrefix(""); nf.setPositivePrefix(""); return equationsToString(prefix, nf); }
public ExponentialFormat( int digits, int exp, boolean sign, boolean trailing ) { this.digits = digits; this.exp = exp; this.sign = sign; this.trailing = trailing; nf = new DecimalFormat( pattern() ); nf.setPositivePrefix("+"); nf.setNegativePrefix("-"); }
public FloatingPointFormat( int w, int d ) { width = w; decimal = d; nf = new DecimalFormat( pattern(w, d) ); nf.setPositivePrefix(" "); nf.setNegativePrefix("-"); }
public ExponentialFormat( int digits, int exp, boolean sign, boolean trailing ) { this.digits = digits; this.exp = exp; this.sign = sign; this.trailing = trailing; nf = new DecimalFormat( pattern() ); nf.setPositivePrefix("+"); nf.setNegativePrefix("-"); }
DecimalFormat formatter = (DecimalFormat)NumberFormat.getCurrencyInstance(); String symbol = formatter.getCurrency().getSymbol(); formatter.setNegativePrefix(symbol+"-"); // or "-"+symbol if that's what you need formatter.setNegativeSuffix("");
/** * @param dfs The decimal format symbols * @param bitcoinConfiguration The Bitcoin configuration to use * @param showNegative True if the negative prefix is allowed * * @return A decimal format suitable for local currency balance representation */ private static DecimalFormat configureLocalDecimalFormat( DecimalFormatSymbols dfs, BitcoinConfiguration bitcoinConfiguration, boolean showNegative ) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(dfs); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(bitcoinConfiguration.getLocalDecimalPlaces()); format.setMinimumFractionDigits(bitcoinConfiguration.getLocalDecimalPlaces()); format.setDecimalSeparatorAlwaysShown(true); if (showNegative) { format.setNegativePrefix("-"); } else { format.setNegativePrefix(""); } return format; }
/** * @param dfs The decimal format symbols * * @return A decimal format suitable for Bitcoin balance representation */ private static DecimalFormat configureBitcoinDecimalFormat(DecimalFormatSymbols dfs, BitcoinSymbol bitcoinSymbol, boolean showNegative) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(dfs); format.setMaximumIntegerDigits(16); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(bitcoinSymbol.decimalPlaces()); format.setMinimumFractionDigits(bitcoinSymbol.decimalPlaces()); format.setDecimalSeparatorAlwaysShown(false); if (showNegative) { format.setNegativePrefix("-"); } else { format.setNegativePrefix(""); } return format; }
public static String numberToCurrencyString(Number damount, boolean bCurrencySign, EscapeFunction f) { LanguageSetting s = languageProvider.vend(); String rv; DecimalFormat d = (DecimalFormat) NumberFormat.getCurrencyInstance(s.locale); if (damount.doubleValue() < 0) { if (d.getNegativePrefix().contains("(")) d.setNegativePrefix(d.getNegativePrefix().replace("(", "-")); if (d.getNegativeSuffix().contains(")")) d.setNegativeSuffix(d.getNegativeSuffix().replace(")", "")); } if (!bCurrencySign) { d.setPositivePrefix(""); d.setPositiveSuffix(""); d.setNegativePrefix("-"); d.setNegativeSuffix(""); } rv = d.format(damount.doubleValue()); rv.replace((char) 160, ' '); return f.escape(rv); }