All Products
Search
Document Center

Resource Orchestration Service:Fn::Calculate

Last Updated:Jun 17, 2026

Fn::Calculate evaluates a string expression and returns the calculation result.

Declaration

  • JSON

    {
      "Fn::Calculate": [
        "expression",
        ndigits,
        [
          <number1>,
          <number2>,
          ...
        ]
      ]
    }
  • YAML

    • Syntax for the full function name:

      Fn::Calculate:
        - expression
        - ndigits
        - - <number1>
          - <number2>
          - ...
    • Syntax for the short form:

      !Calculate 
      	- expression
        - ndigits
        - - <number1>
          - <number2>
          - ...

Parameters

  • expression: an expression of the String type.

  • ndigits: the number of decimal places in the result. The value must be 0 or a positive integer. This parameter takes effect only when the expression contains floating-point numbers.

  • [<number0>, <number1>, <number2>, ... ]: optional. You can define {n} in the expression, where n is the index of a number. During calculation, {n} is replaced with the corresponding number.

Return value

The calculation result of the expression, returned as a Number.

Examples

!Calculate
  - (2+3)/2*3-1
  - 1
!Calculate
  - (2.0+3)/2*3-1
  - 1
!Calculate
  - ({1}+3)/2*3-1
  - 1
  - - 3
    - 5
    - 6
!Calculate
  - ({0}+{1})%3
  - 0
  - - 5
    - 6

The preceding examples return the following results:

5 
6.5
11
2
Note

Integer division truncates decimal places. For example, 5/2 = 2. Therefore, the return value of Fn::Calculate:(2+3)/2*3-1, 1 is 5.