I have a dynamically changing input reading from a file. The numbers are either Int
or Double
. Why does Scala print .0
after every D
Use printf
:
printf("The value is %.0f", x)
For a description of the format string, see this page from the Java SE 6 API documentation.
Note that you can ofcourse also use the Java library from Scala, so other ways to format numbers from Java can also be used from Scala. You can for example use class java.text.DecimalFormat
:
val df = new java.text.DecimalFormat("#####")
println(df.format(x))