Number formatting in Scala?

前端 未结 7 2131
夕颜
夕颜 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:19

    Use type inference, rather than explicit typing.

    scala> val xi = 1
    xi: Int = 1
    
    scala> val xd = 1.0
    xd: Double = 1.0
    
    scala> println(xi)
    1
    
    scala> println(xd)
    1.0
    

提交回复
热议问题