v Change Data Type - Scala

Change Data Type

This tutorial was inspired by the awesome Scala Cookbook.

Change To Integer

// Convert a float to an integer 
32.34.toInt
32
// Convert a string to an integer
"23394".toInt
23394

Change To Double

// Convert a string to a double
"23394".toDouble
23394.0

Change To Float

// Convert a string to float
"23394".toFloat
23394.0
// Convert an integer to float
3923.toFloat
3923.0

Change To Long

// Convert a string to long
"23394".toLong
23394

Change To Short

// Convert a string to short
"23394".toShort
23394

Change To Byte

// Convert a string to byte
"10".toByte
10

Change To String

// Convert an integer to string
2393.toString
2393