October 2021
Intermediate to advanced
500 pages
16h 23m
English
You will sometimes need to convert between floating point numbers and integer numbers. For example, suppose you kept track of a player’s skill level using experience points instead of tracking the level of the player directly, like you do in bounty-board. You might have code that looks like this:
var experiencePoints = 460.25
val playerLevel = experiencePoints / 100
What type do you expect that playerLevel will be? (You can type this code into the REPL, select playerLevel, and press Control-Shift-P [Ctrl-Shift-P] to see the answer for yourself.)
As you may have guessed, playerLevel’s type will be inferred as Double, and its value will be set to 4.6025 when you run this code. This is probably not ...
Read now
Unlock full access