Concept Flow - Integer and Float number types
Start
Define number
Is number whole?
Yes→Integer type
Use integer
Float type
End
Use float
End
The program checks if a number is whole or has decimals, then treats it as Integer or Float accordingly.
a = 5 b = 3.14 puts a.class puts b.class
| Step | Action | Variable | Value | Output |
|---|---|---|---|---|
| 1 | Assign 5 to a | a | 5 | |
| 2 | Assign 3.14 to b | b | 3.14 | |
| 3 | Check class of a | a.class | Integer | |
| 4 | Print class of a | Integer | ||
| 5 | Check class of b | b.class | Float | |
| 6 | Print class of b | Float |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| a | undefined | 5 | 5 | 5 |
| b | undefined | undefined | 3.14 | 3.14 |
Integer and Float in Ruby: - Integer: whole numbers without decimals (e.g., 5) - Float: numbers with decimals (e.g., 3.14) - Use .class to check type - Ruby treats 5 as Integer, 5.0 as Float - Important for math and memory use