SCALA : Overriding the Default Numeric Type


In Scala, there are mainly 7 numeric types .These numeric types are Byte, Char, Double, Float,Int,Long, and Short. All numeric types are object.

Data ranges of Scala’s built-in numeric types are as follows :-

dataranges

Above was the brief introduction of numeric data type .

Now , we will see, how can we override the default Numeric Type .

Here, we assign 100 to a variable , Scala assign it the type Int

Scala > val a = 100
a:Int = 100

Overriding simple numeric type

Approach 1:

Scala > val a =100F
a : Float = 100.0
scala > val a =1000L
a:Long =1000

Approach 2 :

Scala > val a= 0:Byte
a : Byte = 0
Scala > val a= 0:Int
a : Int = 0
Scala > val a= 0:Short
a : Short = 0

You can also define the variable types as below

Scala > val a:Int =10
a :Int =10

About Malti Yadav

An enthusiastic technologist , Scala developer, positive attitude and the desire to go extra mile .
This entry was posted in Scala. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s