Bird
0
0

Which of the following is the correct way to write a float number in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Variables and Data Types
Which of the following is the correct way to write a float number in Ruby?
A5.5
B5-5
C5..5
D5,5
Step-by-Step Solution
Solution:
  1. Step 1: Recall float syntax in Ruby

    Floats use a dot (.) to separate the whole number and decimal parts.
  2. Step 2: Check each option

    5.5 uses a dot correctly. 5,5 uses a comma which is invalid. 5..5 is a range syntax, not a float. 5-5 is subtraction.
  3. Final Answer:

    5.5 -> Option A
  4. Quick Check:

    Float uses dot like 5.5 [OK]
Quick Trick: Floats always use a dot, never a comma. [OK]
Common Mistakes:
  • Using commas instead of dots
  • Confusing ranges with floats
  • Using operators instead of decimal points

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes