Int, Double, Float, Long
In this page:
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
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")
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: