Flowdock
method

mode

Importance_2
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

round away from zero

ROUND_DOWN

round towards zero (truncate)

ROUND_HALF_UP

round up if the appropriate digit >= 5, otherwise truncate (default)

ROUND_HALF_DOWN

round up if the appropriate digit >= 6, otherwise truncate

ROUND_HALF_EVEN

round towards the even neighbor (Banker’s rounding)

ROUND_CEILING

round towards positive infinity (ceil)

ROUND_FLOOR

round towards negative infinity (floor)

Show source
Register or log in to add new notes.