Class: Float
- Inherits:
-
Numeric
- Object
- Numeric
- Float
- Defined in:
- lib/bigdecimal/util.rb,
sig/big_decimal.rbs,
sig/big_decimal_util.rbs
Instance Method Summary collapse
-
#* ⇒ Object
Returns a new Float which is the product of `self` and `other`:.
-
#+ ⇒ Object
Returns a new Float which is the sum of `self` and `other`:.
-
#- ⇒ Object
Returns a new Float which is the difference of `self` and `other`:.
-
#/ ⇒ Object
Returns a new Float which is the result of dividing `self` by `other`:.
-
#to_d(precision = 0) ⇒ BigDecimal
Returns the value of `float` as a BigDecimal.
Instance Method Details
#*(arg0) ⇒ BigDecimal #* ⇒ void
Returns a new Float which is the product of self and other:
f = 3.14
f * 2 # => 6.28
f * 2.0 # => 6.28
f * Rational(1, 2) # => 1.57
f * Complex(2, 0) # => (6.28+0.0i)
1345 1346 |
# File 'sig/big_decimal.rbs', line 1345
def *: (BigDecimal) -> BigDecimal
| ...
|
#+(arg0) ⇒ BigDecimal #+ ⇒ void
Returns a new Float which is the sum of self and other:
f = 3.14
f + 1 # => 4.140000000000001
f + 1.0 # => 4.140000000000001
f + Rational(1, 1) # => 4.140000000000001
f + Complex(1, 0) # => (4.140000000000001+0i)
1360 1361 |
# File 'sig/big_decimal.rbs', line 1360
def +: (BigDecimal) -> BigDecimal
| ...
|
#-(arg0) ⇒ BigDecimal #- ⇒ void
Returns a new Float which is the difference of self and other:
f = 3.14
f - 1 # => 2.14
f - 1.0 # => 2.14
f - Rational(1, 1) # => 2.14
f - Complex(1, 0) # => (2.14+0i)
1375 1376 |
# File 'sig/big_decimal.rbs', line 1375
def -: (BigDecimal) -> BigDecimal
| ...
|
#/(arg0) ⇒ BigDecimal #/ ⇒ void
Returns a new Float which is the result of dividing self by other:
f = 3.14
f / 2 # => 1.57
f / 2.0 # => 1.57
f / Rational(2, 1) # => 1.57
f / Complex(2, 0) # => (1.57+0.0i)
1330 1331 |
# File 'sig/big_decimal.rbs', line 1330
def /: (BigDecimal) -> BigDecimal
| ...
|
#to_d(precision = 0) ⇒ BigDecimal
Returns the value of float as a BigDecimal. The precision parameter is
used to determine the number of 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 Kernel.BigDecimal.
50 51 52 |
# File 'lib/bigdecimal/util.rb', line 50 def to_d(precision=0) BigDecimal(self, precision) end |