Skip to content

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

instance method

Integer#to_s

int.to_s(base=10) → string

Returns a string containing the place-value representation of int with radix base (between 2 and 36).

Example
12345.to_s       #=> "12345"
12345.to_s(2)    #=> "11000000111001"
12345.to_s(8)    #=> "30071"
12345.to_s(10)   #=> "12345"
12345.to_s(16)   #=> "3039"
12345.to_s(36)   #=> "9ix"
78546939656932.to_s(36)  #=> "rubyrules"
See also #to_r #truncate #to_int #upto also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1