split
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (-38)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
split()
public
Splits a BigDecimal number into four parts, returned as an array of values.
The first value represents the sign of the BigDecimal, and is -1 or 1, or 0 if the BigDecimal is Not a Number.
The second value is a string representing the significant digits of the BigDecimal, with no leading zeros.
The third value is the base used for arithmetic (currently always 10) as an Integer.
The fourth value is an Integer exponent.
If the BigDecimal can be represented as 0.xxxxxx*10**n, then xxxxxx is the string of significant digits with no leading zeros, and n is the exponent.
From these values, you can translate a BigDecimal to a float as follows:
sign, significant_digits, base, exponent = a.split f = sign * "0.#{significant_digits}".to_f * (base ** exponent)
(Note that the to_f method is provided as a more convenient way to translate a BigDecimal to a Float.)