Functions - lang.decimal

abs
I

IEEE abs operation.

ceiling
I

Rounds a decimal up to the closest integral value.

floor
I

Rounds a decimal down to the closest integral value.

fromString
I

Return the decimal value represented by s.

max
I

Maximum of one or more decimal values.

min
I

Minimum of one or more decimal values

round
I

Round a decimal to the closest integral value.

sum
I

Sum of zero or more decimal values.

abs

(decimal x)

returns decimal
Isolated Function

IEEE abs operation.

Parameters

  • x decimal
  • decimal value to operate on

  • Return Type

    (decimal)
  • absolute value of x

ceiling

(decimal x)

returns decimal
Isolated Function

Rounds a decimal up to the closest integral value.

Parameters

  • x decimal
  • decimal value to operate on

  • Return Type

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

floor

(decimal x)

returns decimal
Isolated Function

Rounds a decimal down to the closest integral value.

Parameters

  • x decimal
  • decimal value to operate on

  • Return Type

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

fromString

(string s)

returns decimal | error
Isolated Function

Return the decimal value represented by s. 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 value:toString applied to an decimal.

Parameters

  • s string
  • string representation of a decimal

  • Return Type

    (decimal | error)
  • decimal representation of the argument or error

max

(decimal x, decimal... xs)

returns decimal
Isolated Function

Maximum of one or more decimal values.

Parameters

  • x decimal
  • first decimal value

  • xs decimal...
  • other decimal values

  • Return Type

    (decimal)
  • maximum value of x and all the xs

min

(decimal x, decimal... xs)

returns decimal
Isolated Function

Minimum of one or more decimal values

Parameters

  • x decimal
  • first decimal value

  • xs decimal...
  • other decimal values

  • Return Type

    (decimal)
  • minimum value of x and all the xs.

round

(decimal x)

returns decimal
Isolated Function

Round a decimal to the closest integral value. Returns the decimal value that is a mathematical integer and closest to x. If there are two such values, choose the one that is even (this is the round-to-nearest rounding mode, which is the default for IEEE and for Ballerina). Same as Java Math.rint method Same as .NET Math.Round method IEEE 754 roundToIntegralTiesToEven operation Note that <int>x is the same as <int>x.round()

Parameters

  • x decimal
  • decimal value to operate on

  • Return Type

    (decimal)
  • closest decimal value to x that is a mathematical integer

sum

(decimal... xs)

returns decimal
Isolated Function

Sum of zero or more decimal values.

Parameters

  • xs decimal...
  • decimal values to sum

  • Return Type

    (decimal)
  • sum of all the xs; 0 if xs is empty