Documentation

RoundingMode
in package

Specifies a rounding behavior for numerical operations capable of discarding precision.

Each rounding mode indicates how the least significant returned digit of a rounded result is to be calculated. If fewer digits are returned than the digits needed to represent the exact numerical result, the discarded digits will be referred to as the discarded fraction regardless the digits' contribution to the value of the number. In other words, considered as a numerical value, the discarded fraction could have an absolute value greater than one.

Table of Contents

CEILING  = 3
Rounds towards positive infinity.
DOWN  = 2
Rounds towards zero.
FLOOR  = 4
Rounds towards negative infinity.
HALF_CEILING  = 7
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity.
HALF_DOWN  = 6
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
HALF_EVEN  = 9
Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor.
HALF_FLOOR  = 8
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity.
HALF_UP  = 5
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
UNNECESSARY  = 0
Asserts that the requested operation has an exact result, hence no rounding is necessary.
UP  = 1
Rounds away from zero.
__construct()  : mixed
Private constructor. This class is not instantiable.

Constants

CEILING

Rounds towards positive infinity.

public mixed CEILING = 3

If the result is positive, behaves as for UP; if negative, behaves as for DOWN. Note that this rounding mode never decreases the calculated value.

DOWN

Rounds towards zero.

public mixed DOWN = 2

Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never increases the magnitude of the calculated value.

FLOOR

Rounds towards negative infinity.

public mixed FLOOR = 4

If the result is positive, behave as for DOWN; if negative, behave as for UP. Note that this rounding mode never increases the calculated value.

HALF_CEILING

Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity.

public mixed HALF_CEILING = 7

If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN.

HALF_DOWN

Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.

public mixed HALF_DOWN = 6

Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN.

HALF_EVEN

Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor.

public mixed HALF_EVEN = 9

Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for HALF_DOWN if it's even.

Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as "Banker's rounding", and is chiefly used in the USA.

HALF_FLOOR

Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity.

public mixed HALF_FLOOR = 8

If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP.

HALF_UP

Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

public mixed HALF_UP = 5

Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN. Note that this is the rounding mode commonly taught at school.

UNNECESSARY

Asserts that the requested operation has an exact result, hence no rounding is necessary.

public mixed UNNECESSARY = 0

If this rounding mode is specified on an operation that yields a result that cannot be represented at the requested scale, a RoundingNecessaryException is thrown.

UP

Rounds away from zero.

public mixed UP = 1

Always increments the digit prior to a nonzero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.

Methods

__construct()

Private constructor. This class is not instantiable.

private __construct() : mixed
Tags
codeCoverageIgnore
Return values
mixed

Search results