Open In App

Ruby | BigDecimal class floor value

Last Updated : 08 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

BigDecimal#floor() : floor() is a BigDecimal class method which return the floor value of the passed BigDecimal value.

Syntax: BigDecimal.floor()

Parameter:
– BigDecimal value which is to get its floor value
– decimal digits (default = 0)

Return:
– smallest number >= to BigDecimal with a ndigits decimal point precision.
– For -ve precision : Integer with at least ndigits.abs trailing zeros.
– For +ve precision : BigDecimaling point number.

Code #1 : Example for floor() method




# Ruby code for floor() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
a = 42.1**13
  
# declaring BigDecimal
b = -BigDecimal("10")
  
# declaring BigDecimal
c = -(22 ** 7.1) * 10
  
# floor value of a
puts "floor value of a : #{a.floor}\n\n"
  
# floor value of b
puts "floor value of b : #{b.floor}\n\n"
  
# floor value of c
puts "floor value of c : #{c.floor}\n\n"


Output :

floor value of a : 1305170490200643862528

floor value of b : -10

floor value of c : -33978252068

Code #2 : Example for floor() method




# Ruby code for floor() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
a = 12**12 - 27
  
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring BigDecimal
c = BigDecimal('-3')
  
  
# floor value of a
puts "floor value of a : #{a.floor}\n\n"
  
# floor value of b
puts "floor value of b : #{b.floor}\n\n"
  
# floor value of c
puts "floor value of c : #{c.floor}\n\n"


Output :

floor value of a : 8916100448229

floor value of b : -205121100730586399999999999999999999999999999999999999999999999999999999999999999999999999999990

floor value of c : -3



Previous Article
Next Article

Similar Reads

Ruby | BigDecimal class power value
BigDecimal#power() : power() is a BigDecimal class method which returns the BigDecimal value raised to the power of n. Syntax: BigDecimal.power() Parameter: BigDecimal values to find the power the value Return: n - value raised to the power of n prec - precision Code #1 : Example for power() method # Ruby code for power() method # loading BigDecima
1 min read
Ruby | BigDecimal class nonzero? value
BigDecimal#nonzero?() : nonzero?() is a BigDecimal class method which checks whether the BigDecimal value is nonzero. Syntax: BigDecimal.nonzero?() Parameter: BigDecimal values to check Return: self : if value is nonzero; otherwise nil Code #1 : Example for nonzero?() method # Ruby code for nonzero?() method # loading BigDecimal require 'bigdecimal
1 min read
Ruby | BigDecimal class nan? value
BigDecimal#nan?() : nan?() is a BigDecimal class method which checks whether the BigDecimal value is nan value. Syntax: BigDecimal.nan?() Parameter: BigDecimal values to check regarding the NaN value. Return: true : if value is a NaN value; otherwise false Code #1 : Example for nan?() method # Ruby code for nan?() method # loading BigDecimal requir
1 min read
Ruby | BigDecimal class modulo value
BigDecimal#modulo() : modulo() is a BigDecimal class method which returns the modulus from dividing two BigDecimal values. Syntax: BigDecimal.modulo() Parameter: BigDecimal values to divide Return: modulus from dividing two BigDecimal values Code #1 : Example for modulo() method # Ruby code for modulo() method # loading BigDecimal require 'bigdecim
1 min read
Ruby | BigDecimal class inspect value
BigDecimal#inspect() : inspect() is a BigDecimal class method which returns debugging information about the value as a string of comma-separated values . Syntax: BigDecimal.inspect() Parameter: BigDecimal values to find the inspect the value Return: first part - the address second - value as a string final part - current and maximum number of signi
2 min read
Ruby | BigDecimal class hash value
BigDecimal#hash() : hash() is a BigDecimal class method which returns the hash value for the BigDecimal value. Syntax: BigDecimal.hash() Parameter: BigDecimal values to find the hash part of the value Return: hash value for the BigDecimal value Code #1 : Example for hash() method # Ruby code for hash() method # loading BigDecimal require 'bigdecima
2 min read
Ruby | BigDecimal fix class value
BigDecimal#fix() : fix() is a BigDecimal class method which returns the integer value for the BigDecimal value. Syntax: BigDecimal.fix() Parameter: BigDecimal values to find the integer value Return: integer value for the BigDecimal value Code #1 : Example for fix() method # Ruby code for fix() method # loading BigDecimal require 'bigdecimal' # dec
1 min read
Ruby | BigDecimal class frac value
BigDecimal#frac() : frac() is a BigDecimal class method which returns the fractional value for the BigDecimal value. Syntax: BigDecimal.frac() Parameter: BigDecimal values to find the fractional part of the value Return: integer value for the BigDecimal value Code #1 : Example for frac() method # Ruby code for frac() method # loading BigDecimal req
1 min read
Ruby | BigDecimal class exponent value
BigDecimal#exponent() : exponent() is a BigDecimal class method which returns the exponent value for the BigDecimal value. Syntax: BigDecimal.exponent() Parameter: BigDecimal values to find the exponent value Return: exponent value for the BigDecimal value Code #1 : Example for exponent() method # Ruby code for exponent() method # loading BigDecima
1 min read
Ruby | BigDecimal class dup value
BigDecimal#dup() : dup() is a BigDecimal class method which returns the duplicate value for the BigDecimal value. Syntax: BigDecimal.dup() Parameter: BigDecimal values to find the duplicate value Return: duplicate value for the BigDecimal value Code #1 : Example for dup() method # Ruby code for dup() method # loading BigDecimal require 'bigdecimal'
1 min read