Gary Sieling

Fixing scala error java.util.MissingFormatWidthException: %0.2f

If you use a bad number format, you’ll get an error like this:

[error] Exception in thread "main" java.util.MissingFormatWidthException: %0.2f
[error]         at java.util.Formatter$FormatSpecifier.checkNumeric(Formatter.java:3022)
[error]         at java.util.Formatter$FormatSpecifier.checkFloat(Formatter.java:3001)
[error]         at java.util.Formatter$FormatSpecifier.(Formatter.java:2731)
[error]         at java.util.Formatter.parse(Formatter.java:2560)
[error]         at java.util.Formatter.format(Formatter.java:2501)
[error]         at java.util.Formatter.format(Formatter.java:2455)
[error]         at java.lang.String.format(String.java:2940)
[error]         at indexer.GpuConcepts$$anonfun$main$6.apply(GpuConcepts.scala:116)
[error]         at indexer.GpuConcepts$$anonfun$main$6.apply(GpuConcepts.scala:115)
[error]         at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
[error]         at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
[error]         at scala.collection.immutable.List.foreach(List.scala:392)
[error]         at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
[error]         at scala.collection.immutable.List.map(List.scala:296)
[error]         at indexer.GpuConcepts$.main(GpuConcepts.scala:114)
[error]         at indexer.GpuConcepts.main(GpuConcepts.scala)

Instead, do this:

String.format("%-30s: %1.2f ± %1.2f", kv._1, Double.box(kv._2), Double.box(kv._3))
Exit mobile version