Link Menu Expand (external link) Document Search Copy Copied

Perform Maths Operation

Definition

The Perform Math Operations action allows you to execute fundamental arithmetic calculations within your automation workflow. It enables you to process numerical data by adding, subtracting, multiplying, dividing, or finding the absolute difference between two values. Key capabilities include:

  • Performing standard arithmetic (Addition, Subtraction, Multiplication, Division).
  • Calculating the absolute difference between two numbers.
  • Formatting the calculation result as a specific text string (e.g., Currency, Percentage) based on your selected regional culture.

This action is essential for automating financial calculations, adjusting inventory counts, or generating formatted numerical reports without needing external code or complex scripts.



Inputs

1. First Number:

  • Purpose: This is the primary value you want to start your calculation with.
  • Practical Guidance: You can enter a specific number manually (static value) if it is a constant, such as a fixed fee. However, you will most likely use the token picker to select a dynamic value from a previous step, such as an invoice total or item quantity.
  • Use Case Context: You would use this field to input the subtotal of an order before calculating tax.

2. Operation:

  • Purpose: Determines the specific mathematical rule to apply to the numbers provided.
  • Practical Guidance: Select the desired operation from the dropdown list. Options include Add, Subtract, Multiply, Divide, and Absolute Difference.
  • Use Case Context: You would select Multiply to calculate a percentage-based tax or discount.

3. Second Number:

  • Purpose: This is the value that will be applied to the first number based on the selected operation.
  • Practical Guidance: Like the first number, this can be a static value (e.g., typing 0.1 for a 10% rate) or a dynamic value mapped from a previous step (e.g., a discount amount field from a form).
  • Use Case Context: You would use this field to provide the tax rate you want to multiply the subtotal by.

4. Culture:

  • Purpose: Specifies the regional settings (locale) to use when generating the formatted number output. This ensures decimal separators and currency symbols match a specific country or language.
  • Practical Guidance: This is an optional field. If required, select or enter a descriptive culture name from the available options (e.g., English (United States), English (Australia), or French (France)). You can type this statically or map it dynamically if the region changes per workflow run.
  • Use Case Context: You would use this to ensure that a currency result appears as $1,000.00 (US) versus 1 000,00 € (French) depending on the user’s location.

5. Format:

  • Purpose: Defines how the result should be converted into text, such as formatting it as currency, a percentage, or a fixed-point number.
  • Practical Guidance: This is an optional field. Enter a standard numeric format string. Common examples include C for currency, P for percent, and N for number.
  • Use Case Context: You would use this field with the value C to turn a raw calculated number like 1250.5 into a professional currency string like $1,250.50 for an email.



Standard Numeric Format Strings

The Format input field accepts standard numeric format strings to control exactly how your mathematical result is converted into text. A format string consists of an alphabetic character (the format specifier) followed by an optional sequence of digits (the precision specifier). The precision specifier typically determines the number of decimal places or significant digits to display.

1. Currency (C or c):

  • Purpose: Formats the number as a currency amount. The specific currency symbol is driven by the culture setting you specify in the action inputs.
  • Precision Specifier: Dictates the number of decimal places. If omitted, it defaults to two decimal places.
  • Examples: 123.456 formatted with C returns $123.46. -123.456 formatted with C3 returns ($123.456).

2. Exponential (E or e):

  • Purpose: Formats the number using scientific notation, which is ideal for representing extremely large or small numbers compactly.
  • Precision Specifier: Dictates the exact number of decimal places.
  • Examples: 1052.0329112756 formatted with E returns 1.052033E+003. -1052.0329112756 formatted with e2 returns -1.05e+003.

3. Fixed Point (F or f):

  • Purpose: Formats the number with a fixed number of decimal places, regardless of how many digits are in the raw result.
  • Precision Specifier: Dictates the exact number of decimal places to display.
  • Examples: 1234.567 formatted with F returns 1234.57. 1234 formatted with F1 returns 1234.0. -1234.56 formatted with F4 returns -1234.5600.

4. General (G or g):

  • Purpose: Formats the number as either fixed-point or scientific notation, automatically choosing whichever format is more compact.
  • Precision Specifier: Dictates the maximum number of significant digits to display.
  • Examples: -123.456 formatted with G returns -123.456. 123.4546 formatted with G4 returns 123.5. -1.234567890e-25 formatted with G returns -1.23456789E-25.

5. Number (N or n):

  • Purpose: Formats the number with group separators (like commas for thousands) and a decimal point.
  • Precision Specifier: Dictates the exact number of decimal places.
  • Examples: 1234.567 formatted with N returns 1,234.57. 1234 formatted with N1 returns 1,234.0.

6. Percent (P or p):

  • Purpose: Multiplies the raw number by 100 and appends a percentage symbol.
  • Precision Specifier: Dictates the exact number of decimal places to display after the multiplication.
  • Examples: 0.1234 formatted with P returns 12.34 %. 0.1234 formatted with P1 returns 12.3 %.

7. Round-trip (R or r):

  • Purpose: Ensures that a number converted to a text string can be parsed back into the exact same numeric value without any loss of precision.
  • Precision Specifier: This format does not use a precision specifier; if provided, it is ignored.
  • Examples: 123.456789 formatted with R returns 123.456789.

8. Hexadecimal (X or x):

  • Purpose: Converts an integer to its hexadecimal equivalent. Using a capital X produces uppercase characters, while a lowercase x produces lowercase characters.
  • Precision Specifier: Dictates the minimum number of digits to display. If the result has fewer digits, it is padded with leading zeros.
  • Examples: 254 formatted with X returns FE. 254 formatted with x returns fe. 254 formatted with X4 returns 00FE.



Culture Settings and Regional Formatting

The Culture input field determines the specific regional settings (locale) applied when your mathematical result is converted into a formatted text string. When paired with a format string (like C for Currency or N for Number), the culture setting ensures that the output adheres to the precise local conventions of a specific country, language, or region.

1. Standard Syntax:

  • Format Structure: Culture settings in Zenphi use descriptive names representing the language and the region or country.
  • Practical Guidance: If left blank, the system will typically default to standard US English. Explicitly defining the culture is highly recommended for global operations to ensure numbers always appear in the correct local format.

2. Impact on Currency Symbols:

  • Behavior: When using the C (Currency) format, the culture setting dictates which monetary symbol is appended and where it is placed (e.g., before the number or after the number).
  • Example Context: A raw value of 1234.56 formatted as C with the culture English (United States) returns $1,234.56. That exact same value and format with the culture French (France) returns 1 234,56 €. With Japanese (Japan), it returns ¥1,235.

3. Impact on Decimals and Grouping:

  • Behavior: The culture setting changes the characters used for decimal points and thousands (grouping) separators, which is critical for the N, P, and F formats.
  • Example Context: In English (United States), a comma is used for thousands and a period for decimals (1,234.56). In German (Germany), the reverse is true: a period is used for thousands and a comma for decimals (1.234,56).

4. Extensive Regional Support:

  • Global Diversity: The system supports an extensive range of standard geographic and linguistic options, from major global markets to highly specific regional dialects.
  • Example Options:
    • English (United States)
    • English (United Kingdom)
    • French (France)
    • German (Germany)
    • Japanese (Japan)
    • Arabic (Oman)
    • Afar (Djibouti)
    • Afar (Eritrea)
    • English (Europe)
    • Spanish (Mexico)
    • English (Fiji)
    • English (World)



Outputs

1. Result:

  • Data Description: The raw numeric result of the mathematical operation.
  • Workflow Utility: This output is critical for performing subsequent calculations. Because it is a pure number (no currency symbols or formatting), you can pass it into another Perform Math Operations action or use it in logical conditions (e.g., checking if the result is greater than 100).

2. Formatted Number:

  • Data Description: The result of the calculation converted into a text string, applying the specific culture and format rules defined in the inputs.
  • Workflow Utility: This output is designed for display purposes. You would map this token into an email body, a generated document, or a Slack message where you want the number to look professional and human-readable (e.g., displaying $1,500.00 instead of just 1500).



Example Use Cases

1. Calculate Invoice Tax: Multiply a subtotal by a tax rate (e.g., 0.1 for 10%) to determine the tax amount payable.

2. Determine Remaining Budget: Subtract current expenses from a total allocated budget to monitor available funds.

3. Format Currency for Emails: Convert a raw calculated number (e.g., 1250.5) into a professional currency string (e.g., $1,250.50) for customer notifications.

4. Aggregate Order Totals: Add multiple line item costs together to calculate the final transaction value.

5. Calculate Assessment Scores: Divide the total points earned by the maximum possible score to determine a percentage grade.



Example

Scenario: You have an automated expense approval workflow where employees submit reimbursement requests via a Google Form. The company policy states that only 80% of the submitted meal expenses are reimbursable. You need to automatically calculate this reimbursable amount and format it as a currency value (e.g., $80.00) to include in a confirmation email sent back to the employee.

Steps to Implement:

1. Trigger Selection: Start the flow with a Google Form trigger to capture the employee’s submission.

2. Configuration Detail: Add the Perform Math Operations action to process the amount submitted.

  • First Number: Select the meal cost field from the Google Form trigger using the token picker.
  • Operation: Select Multiply from the dropdown menu.
  • Second Number: Enter 0.8 (representing 80%) as a static value.
  • Culture: Enter or select English (United States) (or your specific region option) to ensure the currency symbol matches the employee’s location.
  • Format: Enter C to format the result as a currency string.

Outcome: The workflow automatically calculates the correct 80% reimbursement value. By using the formatting options, the output is immediately ready to be inserted into an email as a professional currency figure (e.g., $40.00) rather than a raw number (e.g., 40), ensuring clear and accurate communication with the employee.



Best Practices

1. Use Raw Results for Logic: Always use the raw numeric result output for subsequent calculations or logical conditions. The formatted number output is a text string and may cause errors in mathematical logic.

2. Chain Actions for Complex Formulas: This action performs one operation at a time. To perform complex formulas, use multiple Perform Math Operations actions in sequence, passing the result of the first into the second.

3. Verify Culture Settings: When using the culture input, ensure you select the correct descriptive option (e.g., English (United Kingdom) for British Pounds, Japanese (Japan) for Japanese Yen) to prevent incorrect currency symbols or decimal formatting.

4. Handle Division by Zero: If using the Divide operation with dynamic data, ensure the second number cannot be zero, as this will cause the workflow to fail.

5. Format for Display Only: Utilize the format and culture inputs specifically when the data is leaving the workflow (e.g., emails, documents, Slack messages) to ensure a professional appearance.