Ruby Integer to_s function with example Last Updated : 03 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The to_s function in Ruby returns a string containing the place-value representation of int with radix base (between 2 and 36). If no base is provided in the parameter then it assumes the base to be 10 and returns. Syntax: number.to_s(base) Parameter: The function takes the number and a base to which is to be converted. If no base is provided in the parameter, then the default parameter is assumed to be 10. Return Value: The function returns a string containing the place-value representation of int with the given radix base. Example #1: Ruby # Ruby program for to_s function # Initializing the number num1 = 10 num2 = 16 num3 = 298 num4 = 183 # Prints the string after # conversion into base puts num1.to_s puts num2.to_s puts num3.to_s(2) puts num4.to_s(8) Output: 10 16 100101010 267 Example #2: Ruby # Ruby program for to_s function # Initializing the number num1 = 120 num2 = 189 num3 = 132 num4 = 8 # Prints the string after # conversion into base puts num1.to_s(5) puts num2.to_s(20) puts num3.to_s(2) puts num4.to_s Output: 440 99 10000100 8 Comment More infoAdvertise with us Next Article Ruby Integer to_s function with example G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby Integer to_r function with example The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: Ruby # Ruby program for to_r function # Initializi 1 min read Ruby Integer to_i function with example The to_i function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. Syntax: number.to_i Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int value. Example #1: Ruby # Ruby program for 1 min read Ruby Integer to_f function with example The to_f function in Ruby converts the value of the number as a float. If it does not fit in float, then it returns infinity. Syntax: number.to_f Parameter: The function takes the integer which is to be converted to float. Return Value: The function returns the float value of the number. Example #1: 1 min read Ruby Integer to_int function with example The to_int function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. It is an alias of to_i function. Syntax: number.to_int Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int valu 1 min read Ruby Integer size() function with example The size() function in Ruby returns the number of bytes in the machine representation of int. Syntax: number.size Parameter: The function takes the integer whose number of bytes is returned. Return Value: The function returns the number of bytes. Example #1: Ruby # Ruby program for size() function # 1 min read Like