Number formatting in Scala?

前端 未结 7 2133
夕颜
夕颜 2021-02-18 23:09

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

相关标签:
7条回答
  • 2021-02-18 23:39

    Starting with Scala 2.10 you can use the f interpolator:

    scala> val x: Double = 1
    x: Double = 1.0
    
    scala> println(f"$x%.0f")
    1
    
    scala> val i = 1
    i: Int = 1
    
    scala> println(f"$i%.0f")
    1
    
    0 讨论(0)
提交回复
热议问题