Ruby Integer to_d() function with example Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The to_d function in Ruby converts the value of int as a BigDecimal. Syntax: number.to_d Parameter: The function takes the integer which is to be converted to BigDecimal. Return Value: The function returns the BigDecimal value of int. Example #1: Ruby # Ruby program for to_d function require 'bigdecimal' require 'bigdecimal/util' # Initializing the number num1 = 5 num2 = 10 ** 100 num3 = 1678 num4 = 189790 # Prints the int as big-decimal puts num1.to_d puts num2.to_d puts num3.to_d puts num4.to_d Output: 0.5e1 0.1e101 0.1678e4 0.18979e6 Example #2: Ruby # Ruby program for to_d function require 'bigdecimal' require 'bigdecimal/util' # Initializing the number num1 = 5 num2 = 19**18 num3 = 2**45 num4 = 888 # Prints the int as big-decimal puts num1.to_d puts num2.to_d puts num3.to_d puts num4.to_d Output: 0.5e1 0.104127350297911241532841e24 0.35184372088832e14 0.888e3 Comment More infoAdvertise with us Next Article Ruby Integer to_d() 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_s function with example 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 whi 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 div() function with example The div() function in Ruby returns the integer division of two numbers. Syntax: (number1).div(number2) Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor. Return Value: The function returns the integer division of two numbers. Exam 1 min read Like