← Back to Scala Course | Chapter 2: Variables & Types | Lesson 2 of 8

Int, Double, Float, Long

In this page:

  1. Int, Double, Float, Long

Int, Double, Float, Long

Int is a 32-bit whole number, Long extends that to 64 bits (with an L suffix on literals), and Double/Float represent 64-bit and 32-bit floating-point numbers respectively (with an f suffix for Float literals). Double is the default type for decimal literals unless a Float is explicitly requested. Choosing the right numeric type matters for both precision and memory usage.

Note: Without an explicit type annotation or suffix, a decimal literal like 3.14 is inferred as Double, not Float.

Example: Int, Double, Float, Long

markup
object Main extends App {
  val age: Int = 30
  val population: Long = 8000000000L
  val price: Double = 19.99
  val temperature: Float = 36.6f

  println(s"$age $population $price $temperature")
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.