Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Float#to_s

to_s → string

Returns a string containing a representation of self; depending of the value of self, the string representation may contain:

  • A fixed-point number.

  • A number in “scientific notation” (containing an exponent).

  • ‘Infinity’.

  • ‘-Infinity’.

  • ‘NaN’ (indicating not-a-number).

    3.14.to_s # => “3.14” (10.1**50).to_s # => “1.644631821843879e+50” (10.1**500).to_s # => “Infinity” (-10.1**500).to_s # => “-Infinity” (0.0/0.0).to_s # => “NaN”

See also #to_r #truncate #to_int #zero? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0