Functions - lang.decimal

abs

IEEE abs operation.

ceiling

Smallest (closest to -∞) floating point value not less than x that is a mathematical integer

floor

Largest (closest to +∞) floating point value not greater than x that is a mathematical integer.

fromString

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.
max

Maximum of all the arguments.

min

Minimum of all the arguments.

round

Floating point value that is a mathematical integer and closest to x. If there are two such integers, 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()

sum

Sum of all the arguments. 0 if no args.

abs

(decimal x)

returns decimal

IEEE abs operation.

Parameters

  • x decimal
  • whose absolute value is to be determined

  • Return Type

    (decimal)
  • absolute value of the argument

ceiling

(decimal x)

returns decimal

Smallest (closest to -∞) floating point value not less than x that is a mathematical integer

Parameters

  • x decimal
  • value to performe ceiling on

  • Return Type

    (decimal)
  • integer ceiling value of the argument in decimal

floor

(decimal x)

returns decimal

Largest (closest to +∞) floating point value not greater than x that is a mathematical integer.

Parameters

  • x decimal
  • whose value to be floored

  • Return Type

    (decimal)
  • floored value

fromString

(string s)

returns decimal | error

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

Maximum of all the arguments.

Parameters

  • x decimal
  • first paramter to check for max value

  • xs decimal[]
  • rest of the parameter to check for max value

  • Return Type

    (decimal)
  • maximum value of all provided values

min

(decimal x, decimal[] xs)

returns decimal

Minimum of all the arguments.

Parameters

  • x decimal
  • first paramter to check for min value

  • xs decimal[]
  • rest of the parameter to check for min value

  • Return Type

    (decimal)
  • minimum value of all provided values

round

(decimal x)

returns decimal

Floating point value that is a mathematical integer and closest to x. If there are two such integers, 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
  • whose value to be rounded

  • Return Type

    (decimal)
  • rounded value

sum

(decimal[] xs)

returns decimal

Sum of all the arguments. 0 if no args.

Parameters

  • xs decimal[]
  • decimal numbers to sum

  • Return Type

    (decimal)
  • sum of the arguments