Ruby | BigDecimal truncate() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report BigDecimal#truncate() : truncate() is a BigDecimal class method which returns the Big decimal by truncating to the nearest integer (by default). Syntax: BigDecimal.truncate() Parameter: BigDecimal values Return: the Big decimal by truncating to the nearest integer (by default). Example #1 : Ruby # Ruby code for BigDecimal.truncate() method # loading library require 'bigdecimal' require 'bigdecimal/util' # declaring bigdecimal a = BigDecimal("10") # declaring bigdecimal b = -BigDecimal("10") # declaring bigdecimal c = -BigDecimal("11.43") # truncate() method puts "BigDecimal a truncate method : #{a.truncate()}\n\n" puts "BigDecimal b truncate method : #{b.truncate()}\n\n" puts "BigDecimal c truncate method : #{c.truncate()}\n\n" Output : BigDecimal a truncate method : 10 BigDecimal b truncate method : -10 BigDecimal c truncate method : -11 Example #2 : Ruby # Ruby code for BigDecimal.truncate() 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') # truncate() method puts "BigDecimal a truncate method : #{a.truncate()}\n\n" puts "BigDecimal b truncate method : #{b.truncate()}\n\n" puts "BigDecimal c truncate method : #{c.truncate()}\n\n" Output : BigDecimal a truncate method : 144 BigDecimal b truncate method : -205121100730586399999999999999999999999999999999999999999999999999999999999999999999999999999990 BigDecimal c truncate method : -3 Comment More infoAdvertise with us Next Article Ruby | BigDecimal sin() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby BigDecimal-class Similar Reads Ruby | BigDecimal sqrt() function BigDecimal#sqrt() : sqrt() is a BigDecimal class method which returns the square root of the value. Syntax: BigDecimal.sqrt() Parameter: BigDecimal values Return: the square root of the value. Example #1 : Ruby # Ruby code for BigDecimal.sqrt() method # loading library require 'bigdecimal' # declari 1 min read Ruby | BigDecimal sub() function BigDecimal#sub() : sub() is a BigDecimal class method which returns the subtraction using a specified value. Syntax: BigDecimal.sub() Parameter: BigDecimal values Return: the subtraction using a specified value. Example #1 : Ruby # Ruby code for BigDecimal.sub() method # loading library require 'big 1 min read Ruby | BigDecimal sin() function BigDecimal#sin() : sin() is a BigDecimal class method which returns the sine of decimal to the specified number of digits of precision, numeric. Syntax: BigDecimal.sin() Parameter: BigDecimal values Return: the sine of decimal to the specified number of digits of precision, numeric. Example #1 : Rub 2 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 zero?() function BigDecimal#zero?() : zero?() is a BigDecimal class method which checks whether the Big decimal value is zero. Syntax: BigDecimal.zero?() Parameter: BigDecimal values Return: true - if the Big decimal value is a zero otherwise return false Example #1 : Ruby # Ruby code for BigDecimal.zero?() method # 1 min read Ruby | BigDecimal sign() function BigDecimal#sign() : sign() is a BigDecimal class method which signs the Big decimal to the nearest integer. Syntax: BigDecimal.sign() Parameter: BigDecimal values Return: signs the Big decimal to the nearest integer. Example #1 : Ruby # Ruby code for BigDecimal.sign() method # loading library requir 1 min read Like