Java Code Examples for java.text.DecimalFormat.setDecimalSeparatorAlwaysShown()

The following are Jave code examples for showing how to use setDecimalSeparatorAlwaysShown() of the java.text.DecimalFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: angel   File: StringUtils.java   Source Code and License Vote up 7 votes
public static String formatPercent(double done, int digits) {
  DecimalFormat percentFormat = new DecimalFormat("0.00%");
  double scale = Math.pow(10.0D, digits + 2);
  double rounded = Math.floor(done * scale);
  percentFormat.setDecimalSeparatorAlwaysShown(false);
  percentFormat.setMinimumFractionDigits(digits);
  percentFormat.setMaximumFractionDigits(digits);
  return percentFormat.format(rounded / scale);
}
 
Example 2
Project: OpenJSharp   File: NumberFormatProviderImpl.java   Source Code and License Vote up 7 votes
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
Example 3
Project: jdk8u-jdk   File: NumberFormatProviderImpl.java   Source Code and License Vote up 6 votes
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
Example 4
Project: openjdk-jdk10   File: NumberFormatProviderImpl.java   Source Code and License Vote up 6 votes
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
Example 5
Project: spark_deep   File: StringUtils.java   Source Code and License Vote up 5 votes
/**
 * 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);
}
 
Example 6
Project: financisto1-holo   File: CurrencyCache.java   Source Code and License Vote up 5 votes
public static DecimalFormat createCurrencyFormat(Currency c) {
	DecimalFormatSymbols dfs = new DecimalFormatSymbols();
	dfs.setDecimalSeparator(charOrEmpty(c.decimalSeparator, dfs.getDecimalSeparator()));
	dfs.setGroupingSeparator(charOrEmpty(c.groupSeparator, dfs.getGroupingSeparator()));
	dfs.setMonetaryDecimalSeparator(dfs.getDecimalSeparator());
	dfs.setCurrencySymbol(c.symbol);

	DecimalFormat df = new DecimalFormat("#,##0.00", dfs);
	df.setGroupingUsed(dfs.getGroupingSeparator() > 0);
	df.setMinimumFractionDigits(c.decimals);
	df.setMaximumFractionDigits(c.decimals);
	df.setDecimalSeparatorAlwaysShown(false);
	return df;
}
 
Example 7
Project: atlant-android   File: DigitsUtils.java   Source Code and License Vote up 4 votes
private static String formatShow(BigDecimal value) {
  DecimalFormat percentFormat = new DecimalFormat(MASK);
  percentFormat.setDecimalSeparatorAlwaysShown(false);
  percentFormat.setRoundingMode(RoundingMode.DOWN);
  return percentFormat.format(value).replace(',', '.');
}