Bird
0
0

Which of the following is a valid way to represent a floating-point number in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Variables and Data Types
Which of the following is a valid way to represent a floating-point number in Ruby?
A3.14
B3,14
C3_14
D3.14f
Step-by-Step Solution
Solution:
  1. Step 1: Identify Ruby float syntax

    Ruby uses a dot (.) as the decimal separator for floats.
  2. Step 2: Evaluate options

    3.14 uses a dot correctly; B uses a comma which is invalid; C uses an underscore which is allowed in integers but not as decimal separator; D uses an invalid suffix 'f'.
  3. Final Answer:

    3.14 -> Option A
  4. Quick Check:

    Valid float uses dot decimal [OK]
Quick Trick: Use dot for decimals in Ruby floats [OK]
Common Mistakes:
  • Using comma instead of dot for decimals
  • Adding suffixes like 'f' to floats
  • Using underscores as decimal separators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes