Ruby | BigDecimal to_int() function Last Updated : 05 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report BigDecimal#to_int() : to_int() is a BigDecimal class method which returns the value as an Integer. Syntax: BigDecimal.to_int() Parameter: BigDecimal values Return: the value as an Integer. Example #1 : Ruby # Ruby code for BigDecimal.to_int() method # loading library require 'bigdecimal' require 'bigdecimal/util' # declaring bigdecimal a = BigDecimal("10") # declaring bigdecimal b = -BigDecimal("10") # declaring bigdecimal c = -BigDecimal("11.43") # to_int() method puts "BigDecimal a to_int method : #{a.to_int()}\n\n" puts "BigDecimal b to_int method : #{b.to_int()}\n\n" puts "BigDecimal c to_int method : #{c.to_int()}\n\n" Output : BigDecimal a to_int method : 10 BigDecimal b to_int method : -10 BigDecimal c to_int method : -11 Example #2 : Ruby # Ruby code for BigDecimal.to_int() method # loading library require 'bigdecimal' require 'bigdecimal/util' # declaring bigdecimal a = BigDecimal('12')*12 # declaring bigdecimal b = BigDecimal('10')-(22 ** 7.1) ** 10 # declaring bigdecimal c = BigDecimal('-3') # to_int() method puts "BigDecimal a to_int method : #{a.to_int()}\n\n" puts "BigDecimal b to_int method : #{b.to_int()}\n\n" puts "BigDecimal c to_int method : #{c.to_int()}\n\n" Output : BigDecimal a to_int method : 144 BigDecimal b to_int method : -205121100730586399999999999999999999999999999999999999999999999999999999999999999999999999999990 BigDecimal c to_int method : -3 Comment More infoAdvertise with us Next Article Ruby | BigDecimal to_d() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby BigDecimal-class Similar Reads Ruby | BigDecimal to_i() function BigDecimal#to_i() : to_i() is a BigDecimal class method which returns the value as an Integer. Syntax: BigDecimal.to_i() Parameter: BigDecimal values Return: the value as an Integer. Example #1 : Ruby # Ruby code for BigDecimal.to_i() method # loading library require 'bigdecimal' require 'bigdecimal 1 min read Ruby | BigDecimal to_r() function BigDecimal#to_r() : to_r() is a BigDecimal class method which returns the value of Big decimal as a rational number. Syntax: BigDecimal.to_r() Parameter: BigDecimal values Return: the value of Big decimal as a rational number Example #1 : Ruby # Ruby code for BigDecimal.to_r() method # loading libra 1 min read Ruby | BigDecimal to_f() function BigDecimal#to_f() : to_f() is a BigDecimal class method which returns a new Float object having approximately the same value as the BigDecimal number. Syntax: BigDecimal.to_f() Parameter: BigDecimal values Return: a new Float object having approximately the same value as the BigDecimal number. Examp 2 min read Ruby | BigDecimal to_s() function BigDecimal#to_s() : to_s() is a BigDecimal class method which returns the value of Big decimal as a string. Syntax: BigDecimal.to_s() Parameter: BigDecimal values Return: the value of Big decimal as a string. Example #1 : Ruby # Ruby code for BigDecimal.to_s() method # loading library require 'bigde 1 min read Ruby | BigDecimal to_d() function BigDecimal#to_d() : to_d() is a BigDecimal class method which returns the self of Big decimal. Syntax: BigDecimal.to_d() Parameter: BigDecimal values Return: the self of Big decimal. Example #1 : Ruby # Ruby code for BigDecimal.to_d() method # loading library require 'bigdecimal' require 'bigdecimal 1 min read Ruby | BigDecimal PI() function BigDecimal#PI() : PI() is a BigDecimal class method which returns the value of pi to the specified number of digits of precision, numeric. Syntax: BigDecimal.PI() Parameter: BigDecimal values Return: the value of pi to the specified number of digits of precision, numeric. Example #1 : Ruby # Ruby co 2 min read Like