0
0
Rubyprogramming~5 mins

Integer and Float number types in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an Integer in Ruby?
An Integer is a whole number without a decimal point, like 5 or -10.
Click to reveal answer
beginner
What is a Float in Ruby?
A Float is a number with a decimal point, like 3.14 or -0.5.
Click to reveal answer
beginner
How do you write a negative Float number in Ruby?
You write a minus sign before the number, like -2.75.
Click to reveal answer
intermediate
What happens if you divide two Integers in Ruby using `/`?
Ruby returns an Integer result if the division is not exact. For example, 5 / 2 returns 2.
Click to reveal answer
beginner
How can you check the type of a number in Ruby?
Use the `.class` method. For example, `5.class` returns Integer, and `3.14.class` returns Float.
Click to reveal answer
Which of these is an Integer in Ruby?
A-0.5
B3.14
C7.0
D42
What type does Ruby assign to the number 6.0?
AString
BInteger
CFloat
DBoolean
What is the result type of 7 / 3 in Ruby?
ABoolean
BInteger
CString
DFloat
How do you find out if a number is an Integer or Float in Ruby?
AUse `.class` method
BUse `.type` method
CUse `.kind` method
DUse `.typeof` method
Which of these is NOT a valid Float in Ruby?
A7
B0.0
C-3.5
D2.718
Explain the difference between Integer and Float number types in Ruby.
Think about numbers with and without decimals.
You got /4 concepts.
    How can you check the type of a number in Ruby and why is it useful?
    Use a method that tells you the object's class.
    You got /3 concepts.