Open In App

Ruby | BigDecimal class frac value

Improve
Improve
Like Article
Like
Save
Share
Report

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
require 'bigdecimal'
  
  
# declaring BigDecimal
b = -BigDecimal("10")
  
puts "frac example 2 : #{b.frac()}\n\n"
     


Output :

frac example 2 : -0.0

Code #2 : Example for frac() method




# Ruby code for frac() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring BigDecimal
c = BigDecimal('-3')
  
  
puts "frac example 2 : #{b.frac()}\n\n"
  
puts "frac example 3 : #{c.frac()}\n\n"


Output :

frac example 2 : -0.0

frac example 3 : -0.0

Last Updated : 08 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads