mode
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (38)
- 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?
mode(p1, p2 = v2)
public
Controls handling of arithmetic exceptions and rounding. If no value is supplied, the current value is returned.
Six values of the mode parameter control the handling of arithmetic exceptions:
BigDecimal::EXCEPTION_NaN BigDecimal::EXCEPTION_INFINITY BigDecimal::EXCEPTION_UNDERFLOW BigDecimal::EXCEPTION_OVERFLOW BigDecimal::EXCEPTION_ZERODIVIDE BigDecimal::EXCEPTION_ALL
For each mode parameter above, if the value set is false, computation continues after an arithmetic exception of the appropriate type. When computation continues, results are as follows:
EXCEPTION_NaN |
NaN |
EXCEPTION_INFINITY |
+infinity or -infinity |
EXCEPTION_UNDERFLOW |
0 |
EXCEPTION_OVERFLOW |
+infinity or -infinity |
EXCEPTION_ZERODIVIDE |
+infinity or -infinity |
One value of the mode parameter controls the rounding of numeric values: BigDecimal::ROUND_MODE. The values it can take are:
ROUND_UP, :up |
round away from zero |
ROUND_DOWN, :down, :truncate |
|
ROUND_HALF_UP, :half_up, :default |
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round away from zero. (default) |
ROUND_HALF_DOWN, :half_down |
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards zero. |
ROUND_HALF_EVEN, :half_even, :banker |
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards the even neighbor (Banker’s rounding) |
ROUND_CEILING, :ceiling, :ceil |
|
ROUND_FLOOR, :floor |