# Functions

 abs IReturns the IEEE absolute value of a decimal value. ceiling IRounds a decimal up to the closest integral value. floor IRounds a decimal down to the closest integral value. fromString IReturns the decimal value represented by a string. max IReturns the maximum of one or more decimal values. min IReturns the minimum of one or more decimal values. quantize IIEEE quantize operation. round IRound a decimal to a specified number of digits. sum IReturns the sum of zero or more decimal values.

## abs

``function abs(decimal x) returns decimal``
Isolated Function

Returns the IEEE absolute value of a decimal value.

### Parameters

• x
• decimal value to operate on

### Return Type

(decimal)

absolute value of parameter `x`

## ceiling

``function ceiling(decimal x) returns decimal``
Isolated Function

Rounds a decimal up to the closest integral value.

### Parameters

• x
• decimal value to operate on

### Return Type

(decimal)

smallest (closest to -∞) decimal value not less than parameter `x` that is a mathematical integer

## floor

``function floor(decimal x) returns decimal``
Isolated Function

Rounds a decimal down to the closest integral value.

### Parameters

• x
• decimal value to operate on

### Return Type

(decimal)

largest (closest to +∞) decimal value not greater than parameter `x` that is a mathematical integer.

## fromString

``function fromString(string s) returns decimal | error``
Isolated Function

Returns the decimal value represented by a string.

`s` must follow the syntax of DecimalFloatingPointNumber as defined by the Ballerina specification with the following modifications

• the DecimalFloatingPointLiteral may have a leading `+` or `-` sign
• a FloatingPointTypeSuffix is not allowed

This is the inverse of function `value:toString` applied to an `decimal`.

### Parameters

• s
• string representation of a decimal

### Return Type

()

decimal representation of the argument or error

## max

``function max(decimal x, decimal... xs) returns decimal``
Isolated Function

Returns the maximum of one or more decimal values.

### Parameters

• x
• first decimal value

### Return Type

(decimal)

maximum value of parameter `x` and all the parameter `xs`

## min

``function min(decimal x, decimal... xs) returns decimal``
Isolated Function

Returns the minimum of one or more decimal values.

### Parameters

• x
• first decimal value

### Return Type

(decimal)

minimum value of parameter `x` and all the parameter `xs`.

## quantize

``function quantize(decimal x, decimal y) returns decimal``
Isolated Function

IEEE quantize operation.

### Parameters

• x
• decimal value to operate on

• y
• decimal value from which to get the quantum

### Return Type

(decimal)

`x` with the quantum of `y`

## round

``function round(decimal x, int fractionDigits) returns decimal``
Isolated Function

Round a decimal to a specified number of digits. Returns the decimal value that has an exponent of `-fractionDigits` and is closest to `x`. If there are two such values, returns the one whose final digit is even (this is the round-to-nearest rounding mode, which is the default for IEEE and for Ballerina). A value of `fractionDigits` greater than 0 thus corresponds to the number of digits after the decimal point being `fractionDigits`; a value of 0 for `fractionDigits` rounds to an integer. Note that IEEE 754 roundToIntegralTiesToEven operation differs from `round` with `fractionDigits` as 0, in that roundToIntegralTiesToEven will return a value with a positive exponent when the operand has a positive exponent. Note that `<int>x` is the same as `<int>x.round(0)`.

### Parameters

• x
• decimal value to operate on

• fractionDigits (default 0)
• the number of digits after the decimal point

### Return Type

(decimal)

closest decimal value to `x` that is an integral multiple of 10 raised to the power of `-fractionDigits`

## sum

``function sum(decimal... xs) returns decimal``
Isolated Function

Returns the sum of zero or more decimal values.

### Parameters

• xs decimal...
• decimal values to sum

### Return Type

(decimal)

sum of all the parameter `xs`; 0 if parameter `xs` is empty