Example usage for java.text DecimalFormatSymbols setMonetaryDecimalSeparator

List of usage examples for java.text DecimalFormatSymbols setMonetaryDecimalSeparator

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols setMonetaryDecimalSeparator.

Prototype

public void setMonetaryDecimalSeparator(char sep) 

Source Link

Document

Sets the monetary decimal separator.

Usage

From source file:Main.java

public static String safeDoubleToCurrency(Double val) {
    BigDecimal value = BigDecimal.valueOf(val);
    DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
    DecimalFormatSymbols formatRp = new DecimalFormatSymbols();

    formatRp.setCurrencySymbol("");
    formatRp.setMonetaryDecimalSeparator('.');
    formatRp.setGroupingSeparator(',');

    kursIndonesia.setDecimalFormatSymbols(formatRp);
    kursIndonesia.setParseBigDecimal(true);
    if (val < 1)
        kursIndonesia.setMaximumFractionDigits(8);
    else if (val < 10)
        kursIndonesia.setMaximumFractionDigits(6);
    else if (val < 100)
        kursIndonesia.setMaximumFractionDigits(4);

    return kursIndonesia.format(value);
}