java.text.DecimalFormat#setMultiplier ( )源码实例Demo

下面列出了java.text.DecimalFormat#setMultiplier ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LagMonitor   文件: EnvironmentCommand.java
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));
}
 
源代码2 项目: LagMonitor   文件: EnvironmentCommand.java
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));
}
 
源代码3 项目: j2objc   文件: DecimalFormatTest.java
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()));
}
 
源代码4 项目: j2objc   文件: DecimalFormatTest.java
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));
}
 
源代码5 项目: j2objc   文件: DecimalFormatTest.java
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));
}
 
源代码6 项目: dragonwell8_jdk   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码7 项目: TencentKona-8   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码10 项目: openjdk-jdk9   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码11 项目: jdk8u_jdk   文件: Bug8165466.java
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
                + "]");
    }
}
 
源代码12 项目: morpheus-core   文件: Parser.java
/**
 * 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;
}
 
源代码13 项目: morpheus-core   文件: Printer.java
/**
 * 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;
}