Code example for DecimalFormat

Methods: getDecimalFormatSymbolssetDecimalFormatSymbolsformat

0
import java.util.Locale; 
import tests.support.Support_Locale; 
 
public class DecimalFormatTest extends junit.framework.TestCase {
    public void test_exponentSeparator() throws Exception { 
        DecimalFormat df = new DecimalFormat("0E0");
        assertEquals("1E4", df.format(12345.));
 
        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
        dfs.setExponentSeparator("-useless-api-");
        df.setDecimalFormatSymbols(dfs);
        assertEquals("1-useless-api-4", df.format(12345.));
    } 
 
    public void test_setMaximumFractionDigitsAffectsRoundingMode() throws Exception { 
        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
        df.setMaximumFractionDigits(0);
        df.setRoundingMode(RoundingMode.HALF_UP);
        assertEquals("-0", df.format(-0.2));
        df.setMaximumFractionDigits(1);