Skip to content

Commit 4f0894c

Browse files
mrzasamrkn
authored andcommitted
Document precision=0 and ndigits=0 for converting from Float
1 parent 223d193 commit 4f0894c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,9 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
35003500
* in the value, the result is rounded to that number of digits,
35013501
* according to the current rounding mode; see BigDecimal.mode.
35023502
*
3503+
* When +ndigits+ is 0, the number of digits to correctly represent a float number
3504+
* is determined automatically.
3505+
*
35033506
* Returns +value+ converted to a \BigDecimal, depending on the type of +value+:
35043507
*
35053508
* - Integer, Float, Rational, Complex, or BigDecimal: converted directly:

lib/bigdecimal/util.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ class Float < Numeric
3333
#
3434
# Returns the value of +float+ as a BigDecimal.
3535
# The +precision+ parameter is used to determine the number of
36-
# significant digits for the result (the default is Float::DIG).
36+
# significant digits for the result. When +precision+ is set to +0+,
37+
# the number of digits to represent the float being converted is determined
38+
# automatically.
39+
# The default +precision+ is +0+.
3740
#
3841
# require 'bigdecimal'
3942
# require 'bigdecimal/util'
4043
#
4144
# 0.5.to_d # => 0.5e0
45+
# 1.234.to_d # => 0.1234e1
4246
# 1.234.to_d(2) # => 0.12e1
4347
#
4448
# See also BigDecimal::new.

0 commit comments

Comments
 (0)