Ruby Language Numbers Converting a number to a string

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Fixnum#to_s takes an optional base argument and represents the given number in that base:

2.to_s(2)   # => "10"
3.to_s(2)   # => "11"
3.to_s(3)   # => "10"
10.to_s(16) # => "a"

If no argument is provided, then it represents the number in base 10

2.to_s # => "2"
10423.to_s # => "10423"


Got any Ruby Language Question?