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, andAbsolute Difference. - Use Case Context: You would select
Multiplyto 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.1for 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), orFrench (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) versus1 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
Cfor currency,Pfor percent, andNfor number. - Use Case Context: You would use this field with the value
Cto turn a raw calculated number like1250.5into a professional currency string like$1,250.50for 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.456formatted withCreturns$123.46.-123.456formatted withC3returns($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.0329112756formatted withEreturns1.052033E+003.-1052.0329112756formatted withe2returns-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.567formatted withFreturns1234.57.1234formatted withF1returns1234.0.-1234.56formatted withF4returns-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.456formatted withGreturns-123.456.123.4546formatted withG4returns123.5.-1.234567890e-25formatted withGreturns-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.567formatted withNreturns1,234.57.1234formatted withN1returns1,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.1234formatted withPreturns12.34 %.0.1234formatted withP1returns12.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.456789formatted withRreturns123.456789.
8. Hexadecimal (X or x):
- Purpose: Converts an integer to its hexadecimal equivalent. Using a capital
Xproduces uppercase characters, while a lowercasexproduces 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:
254formatted withXreturnsFE.254formatted withxreturnsfe.254formatted withX4returns00FE.
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.56formatted asCwith the cultureEnglish (United States)returns$1,234.56. That exact same value and format with the cultureFrench (France)returns1 234,56 €. WithJapanese (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, andFformats. - Example Context: In
English (United States), a comma is used for thousands and a period for decimals (1,234.56). InGerman (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.00instead of just1500).
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
Multiplyfrom 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
Cto 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.