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

The following examples show how to use java.text.DecimalFormat#setMultiplier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnvironmentCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printExtendOsInfo(CommandSender sender) {
    NativeManager nativeData = plugin.getNativeData();

    //cpu
    double systemCpuLoad = nativeData.getCPULoad();
    double processCpuLoad = nativeData.getProcessCPULoad();

    //these numbers are in percent (0.01 -> 1%)
    //we want to to have four places in a human readable percent value to multiple it with 100
    DecimalFormat decimalFormat = new DecimalFormat("###.#### %");
    decimalFormat.setMultiplier(100);
    String systemLoadFormat = decimalFormat.format(systemCpuLoad);
    String processLoadFormat = decimalFormat.format(processCpuLoad);

    sendMessage(sender,"System Usage", systemLoadFormat);
    sendMessage(sender,"Process Usage", processLoadFormat);

    //swap
    long totalSwap = nativeData.getTotalSwap();
    long freeSwap = nativeData.getFreeSwap();
    sendMessage(sender, "Total Swap", readableBytes(totalSwap));
    sendMessage(sender, "Free Swap", readableBytes(freeSwap));

    //RAM
    long totalMemory = nativeData.getTotalMemory();
    long freeMemory = nativeData.getFreeMemory();
    sendMessage(sender, "Total OS RAM", readableBytes(totalMemory));
    sendMessage(sender, "Free OS RAM", readableBytes(freeMemory));
}
 
Example 2
Source File: EnvironmentCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printExtendOsInfo(CommandSender sender) {
    NativeManager nativeData = plugin.getNativeData();

    //cpu
    double systemCpuLoad = nativeData.getCPULoad();
    double processCpuLoad = nativeData.getProcessCPULoad();

    //these numbers are in percent (0.01 -> 1%)
    //we want to to have four places in a human readable percent value to multiple it with 100
    DecimalFormat decimalFormat = new DecimalFormat("###.#### %");
    decimalFormat.setMultiplier(100);
    String systemLoadFormat = decimalFormat.format(systemCpuLoad);
    String processLoadFormat = decimalFormat.format(processCpuLoad);

    sendMessage(sender,"System Usage", systemLoadFormat);
    sendMessage(sender,"Process Usage", processLoadFormat);

    //swap
    long totalSwap = nativeData.getTotalSwap();
    long freeSwap = nativeData.getFreeSwap();
    sendMessage(sender, "Total Swap", readableBytes(totalSwap));
    sendMessage(sender, "Free Swap", readableBytes(freeSwap));

    //RAM
    long totalMemory = nativeData.getTotalMemory();
    long freeMemory = nativeData.getFreeMemory();
    sendMessage(sender, "Total OS RAM", readableBytes(totalMemory));
    sendMessage(sender, "Free OS RAM", readableBytes(freeMemory));
}
 
Example 3
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testBigDecimalICUConsistency() {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    df.setMaximumFractionDigits(2);
    df.setMultiplier(2);
    assertEquals(df.format(BigDecimal.valueOf(0.16)),
            df.format(BigDecimal.valueOf(0.16).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(0.0293)),
            df.format(BigDecimal.valueOf(0.0293).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(0.006)),
            df.format(BigDecimal.valueOf(0.006).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(0.00283)),
            df.format(BigDecimal.valueOf(0.00283).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(1.60)),
    df.format(BigDecimal.valueOf(1.60).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(15)),
            df.format(BigDecimal.valueOf(15).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(170)),
            df.format(BigDecimal.valueOf(170).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(234.56)),
            df.format(BigDecimal.valueOf(234.56).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(0)),
    df.format(BigDecimal.valueOf(0).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(-1)),
    df.format(BigDecimal.valueOf(-1).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(-10000)),
    df.format(BigDecimal.valueOf(-10000).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(-0.001)),
            df.format(BigDecimal.valueOf(-0.001).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(1234567890.1234567)),
            df.format(BigDecimal.valueOf(1234567890.1234567).doubleValue()));
    assertEquals(df.format(BigDecimal.valueOf(1.234567E100)),
            df.format(BigDecimal.valueOf(1.234567E100).doubleValue()));
}
 
Example 4
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void assertDecFmtWithMultiplierAndFraction(String value, int multiplier, int fraction, String expectedResult) {
    DecimalFormat df = (DecimalFormat)NumberFormat.getInstance();
    df.setMultiplier(multiplier);
    df.setMaximumFractionDigits(fraction);
    BigDecimal d = new BigDecimal(value);
    assertEquals(expectedResult, df.format(d));
}
 
Example 5
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void assertDecFmtWithMultiplierAndFractionByLocale(String value, int multiplier, int fraction, Locale locale, String expectedResult) {
    DecimalFormat df = (DecimalFormat)NumberFormat.getIntegerInstance(locale);
    df.setMultiplier(multiplier);
    df.setMaximumFractionDigits(fraction);
    BigDecimal d = new BigDecimal(value);
    assertEquals(expectedResult, df.format(d));
}
 
Example 6
Source File: Bug8165466.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 7
Source File: Bug8165466.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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 8
Source File: Bug8165466.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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 9
Source File: Bug8165466.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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 10
Source File: Bug8165466.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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 11
Source File: Bug8165466.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 12
Source File: Parser.java    From morpheus-core with Apache License 2.0 2 votes vote down vote up
/**
 * 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 13
Source File: Printer.java    From morpheus-core with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}