How do I do casting in Scala?
Solution 1:
You can do (myDouble/myInt).toInt
. You can also do toDouble
, toLong
, and toFloat
.
Solution 2:
My prefered way is to add a rounding method, to reduce any potential suprise in the conversion behavior:
val divide = (myDouble/myInt).ceil.toInt
or
val divide = (myDouble/myInt).floor.toInt