mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/bigdecimal] Document precision=0 and ndigits=0 for converting from Float
https://github.com/ruby/bigdecimal/commit/4f0894c6c0
This commit is contained in:
parent
a58cbddd57
commit
b8e804e410
2 changed files with 8 additions and 1 deletions
|
@ -3500,6 +3500,9 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
|
|||
* in the value, the result is rounded to that number of digits,
|
||||
* according to the current rounding mode; see BigDecimal.mode.
|
||||
*
|
||||
* When +ndigits+ is 0, the number of digits to correctly represent a float number
|
||||
* is determined automatically.
|
||||
*
|
||||
* Returns +value+ converted to a \BigDecimal, depending on the type of +value+:
|
||||
*
|
||||
* - Integer, Float, Rational, Complex, or BigDecimal: converted directly:
|
||||
|
|
|
@ -33,12 +33,16 @@ class Float < Numeric
|
|||
#
|
||||
# Returns the value of +float+ as a BigDecimal.
|
||||
# The +precision+ parameter is used to determine the number of
|
||||
# significant digits for the result (the default is Float::DIG).
|
||||
# significant digits for the result. When +precision+ is set to +0+,
|
||||
# the number of digits to represent the float being converted is determined
|
||||
# automatically.
|
||||
# The default +precision+ is +0+.
|
||||
#
|
||||
# require 'bigdecimal'
|
||||
# require 'bigdecimal/util'
|
||||
#
|
||||
# 0.5.to_d # => 0.5e0
|
||||
# 1.234.to_d # => 0.1234e1
|
||||
# 1.234.to_d(2) # => 0.12e1
|
||||
#
|
||||
# See also BigDecimal::new.
|
||||
|
|
Loading…
Reference in a new issue