Source Code

Decimal floating point arithmetic. The focus of this module is the Decimal type which performs computations using decimal floating point arithmetic. An of Decimal may be obtained by calling decimalNumber() or parseDecimal().

A Rounding is used to specify how results of calculations should be rounded, and an instance may be obtained by calling round(). The implicitRounding function may be used to associate a Rounding with a computation, performing the whole computation with an implicit rounding strategy.

Platform: Java
Packages
ceylon.decimal
Dependencies
ceylon.whole1.3.3
java.base7
Values
ceilingSource Codeshared ceiling ceiling

Round towards positive infinity.

downSource Codeshared down down

Round towards zero.

floorSource Codeshared floor floor

Round towards negative infinity.

halfDownSource Codeshared halfDown halfDown

Round towards the nearest neighbour, or round down if there are two nearest neighbours.

halfEvenSource Codeshared halfEven halfEven

Round towards the nearest neighbour, or round towards the even neighbour if there are two nearest neighbours.

halfUpSource Codeshared halfUp halfUp

Round towards the nearest neighbour, or round up if there are two nearest neighbours.

implicitRoundingSource Codeshared Rounding? implicitRounding

The rounding currently being used implicitly by the Decimal operators +, -, *, / and ^ (or equivalently, the methods plus(), minus(), times(), divided(), and power()).

oneSource Codeshared Decimal one

A Decimal instance representing one.

tenSource Codeshared Decimal ten

A Decimal instance representing ten.

unlimitedPrecisionSource Codeshared Rounding unlimitedPrecision

Unlimited precision.

unnecessarySource Codeshared unnecessary unnecessary

Asserts that rounding will not be required causing an exception to be thrown if it is.

upSource Codeshared up up

Round away from zero.

zeroSource Codeshared Decimal zero

A Decimal instance representing zero.

Functions
decimalNumberSource Codeshared Decimal decimalNumber(Whole|Integer|Float number, Rounding? rounding = null)

The given number converted to a Decimal.

Parameters:
  • rounding = null
implicitlyRoundedSource Codeshared Decimal implicitlyRounded(Decimal calculate(), Rounding rounding)

Performs an arbitrary calculation with the given rounding used implicitly when arithmetic operators are applied to Decimal operands.

During a call to this method the Decimal operators +, -, *, / and ^ (or equivalently, the methods plus(), minus(), times(), divided(), and power()) will implicitly use the given rounding. The behaviour of all other Decimal methods are unchanged during a call to this function.

The implicit rounding will only take effect on the current thread. The calculate() function may itself call implicitlyRounded() to apply a different implicit rounding for a sub-calculation.

parseDecimalSource Codeshared Decimal? parseDecimal(String str)

The Decimal represented by the given string, or null if the given string does not represent a Decimal.

roundSource Codeshared Rounding round(Integer precision, Mode mode)

Creates a rounding with the given precision and mode.

Interfaces
DecimalSource Codeshared Decimal

A decimal floating point number. This class provides support for fixed and arbitrary precision numbers. Values are immutable and represented as unscaled * 10^(-scale). Methods without an explicit Rounding parameter use unlimitedPrecision (unless documented otherwise) except for plus(), minus(), times(), divided() and power() whose implicit rounding is subject to the rounding specified in implicitlyRounded().

Classes
DividedWithRemainderSource Codeshared DividedWithRemainder
ModeSource Codeshared abstract Mode

A strategy for rounding the result of an operation on two Decimals.

RoundingSource Codeshared abstract Rounding

Holds precision and rounding information for use in decimal arithmetic. A precision of 0 means unlimited precision.

ceilingSource Codeshared ceiling

Round towards positive infinity.

downSource Codeshared down

Round towards zero.

floorSource Codeshared floor

Round towards negative infinity.

halfDownSource Codeshared halfDown

Round towards the nearest neighbour, or round down if there are two nearest neighbours.

halfEvenSource Codeshared halfEven

Round towards the nearest neighbour, or round towards the even neighbour if there are two nearest neighbours.

halfUpSource Codeshared halfUp

Round towards the nearest neighbour, or round up if there are two nearest neighbours.

unnecessarySource Codeshared unnecessary

Asserts that rounding will not be required causing an exception to be thrown if it is.

upSource Codeshared up

Round away from zero.