获取java.util.IllegalFormatConversionException:f!= java.lang.String使用正确的格式%f为双打

时间:2017-11-07 20:25:29

标签: java number-formatting

主要的以下代码假设使用System.out.printf将结果输出到两个小数位,以使用%f格式化double值。 但是,我收到以下错误:

#NA

带有格式化print语句的部分代码:

Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
    at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
    at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2806)
    at java.util.Formatter$FormatSpecifier.print(Formatter.java:2753)
    at java.util.Formatter.format(Formatter.java:2520)
The total bonus for this employee is $  at java.io.PrintStream.format(PrintStream.java:970)
    at java.io.PrintStream.printf(PrintStream.java:871)
    at Assignment1.Q2.TestBonusOnSavings.main(TestBonusOnSavings.java:36)
C:\Users\User\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 6 seconds)

0 个答案:

没有答案