Ruby Float to_d() – BigDecimal method with example
Last Updated :
14 Apr, 2022
Float to_d() is a float class method which return a BigDecimal representation of the float value
Syntax: float.to_d()
Parameter: float value as argument precision parameter : number of significant digits for the result
Return: BigDecimal representation of the float value with a significant number of digits for the result.
Example #1 :
Ruby
require 'bigdecimal'
require 'bigdecimal/util'
a = 0 . 767
b = 2999 . 011
puts "BigDecimal a :
puts "BigDecimal b :
|
Output :
BigDecimal a : 0.767E0
BigDecimal b : 0.2999011E4
Example #2 :
Ruby
require 'bigdecimal'
require 'bigdecimal/util'
a = 0 . 767
b = 2999 . 011
c = 2 . 0000
puts "BigDecimal a :
puts "BigDecimal b :
puts "BigDecimal c :
|
Output :
BigDecimal a : 0.77E0
BigDecimal b : 0.2999E4
BigDecimal c : 0.2E1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...