Title: Change Data Type
Slug: change_data_type
Summary: Change Data Type Using Scala.
Date: 2017-01-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon

This tutorial was inspired by the awesome Scala Cookbook.

Change To Integer


In [1]:
// Convert a float to an integer 
32.34.toInt


Out[1]:
32

In [2]:
// Convert a string to an integer
"23394".toInt


Out[2]:
23394

Change To Double


In [3]:
// Convert a string to a double
"23394".toDouble


Out[3]:
23394.0

Change To Float


In [4]:
// Convert a string to float
"23394".toFloat


Out[4]:
23394.0

In [5]:
// Convert an integer to float
3923.toFloat


Out[5]:
3923.0

Change To Long


In [6]:
// Convert a string to long
"23394".toLong


Out[6]:
23394

Change To Short


In [7]:
// Convert a string to short
"23394".toShort


Out[7]:
23394

Change To Byte


In [10]:
// Convert a string to byte
"10".toByte


Out[10]:
10

Change To String


In [9]:
// Convert an integer to string
2393.toString


Out[9]:
2393