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

The following are Jave code examples for showing how to use setMultiplier() 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: openjdk-jdk10   File: Bug8165466.java   Source Code and License Vote up 4 votes
public static void main(String[] args) {
    DecimalFormat nf = (DecimalFormat) DecimalFormat
            .getPercentInstance(Locale.US);
    nf.setMaximumFractionDigits(3);
    nf.setMinimumFractionDigits(0);
    nf.setMultiplier(1);

    double d = 0.005678;
    String result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    d = 0.00;
    result = nf.format(d);
    if (!result.equals("0%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0%, Found: " + result
                + "]");
    }

    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    //checking with the non zero value
    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    d = 9.00;
    result = nf.format(d);
    if (!result.equals("9%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 9%, Found: " + result
                + "]");
    }

    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }
}
 
Example 2
Project: morpheus-core   File: Parser.java   Source Code and License Vote up 2 votes
/**
 * Returns a newly created DecimalFormat object
 * @param pattern       the format pattern
 * @param multiplier    the multiplier
 * @return              the formatter
 */
private static DecimalFormat createDecimalFormat(String pattern, int multiplier) {
    final DecimalFormat decimalFormat = new DecimalFormat(pattern);
    decimalFormat.setMultiplier(multiplier);
    return decimalFormat;
}
 
Example 3
Project: morpheus-core   File: Printer.java   Source Code and License Vote up 2 votes
/**
 * Returns a newly created DecimalFormat object
 * @param pattern       the format pattern
 * @param multiplier    the multiplier
 * @return              the formatter
 */
private static DecimalFormat createDecimalFormat(String pattern, int multiplier) {
    final DecimalFormat decimalFormat = new DecimalFormat(pattern);
    decimalFormat.setMultiplier(multiplier);
    return decimalFormat;
}