Calculations
Add calculated fields that update automatically based on user input.
What are Calculated Fields?
Calculated fields display computed values based on other form fields. They update in real time as users enter data, providing instant feedback for quotes, totals, taxes, and complex formulas.
Perfect for order forms, quote calculators, and any form that needs mathematical operations.
Adding a Calculated Field
- In the form editor, add a Calculated Field block
- Write your formula in the Calculation panel
- Reference other fields by their names
- Test in preview mode
The field appears as a read-only input that updates automatically.
Writing Formulas
Formulas use standard mathematical operators and function calls:
Basic Operators
quantity * price
(subtotal + tax) - discount
hourly_rate * hours_worked
Field References
Reference other fields by their exact field names:
base_price * 1.2 // 20% markup
length * width * height // Volume calculation
Field names are case-sensitive and cannot contain spaces. Use underscores or camelCase.
Mathematical Functions
Basic Math
abs(value) // Absolute value
round(value, 2) // Round to 2 decimal places
ceil(value) // Round up
floor(value) // Round down
pow(base, exponent) // Power
sqrt(value) // Square root
Conditional Logic
if(condition, true_value, false_value)
if(quantity > 10, price * 0.9, price) // 10% bulk discount
Complex Example
// Shipping calculator
if(weight <= 2, 5.99,
if(weight <= 5, 9.99,
weight * 2.50))
Common Formulas
Order Total with Tax
(quantity * unit_price) * (1 + tax_rate / 100)
Area Calculation
length * width
Volume Calculation
length * width * height
Percentage Discount
original_price * (1 - discount_percentage / 100)
Compound Interest
principal * pow(1 + annual_rate / 100, years)
BMI Calculator
weight / pow(height / 100, 2)
Formatting Results
Control how calculated values display:
Currency Formatting
Format: Currency
Symbol: $
Decimals: 2
Result: $42.99
Percentage
Format: Percentage
Decimals: 1
Result: 15.5%
Number with Units
Format: Number
Suffix: " sq ft"
Result: 250 sq ft
Custom Formatting
Format: Custom
Pattern: "Total: {value} items"
Result: Total: 42 items
Real-Time Updates
Calculated fields update instantly when referenced fields change:
- Text inputs — on every keystroke
- Dropdowns — when selection changes
- Checkboxes — when checked/unchecked
- Radio buttons — when selection changes
No submit button required. Users see results immediately.
Conditional Calculations
Advanced conditional calculations require SkunkForms Pro.
Use if-then logic for complex scenarios:
Tiered Pricing
if(quantity >= 100, unit_price * 0.8,
if(quantity >= 50, unit_price * 0.9,
unit_price))
Membership Discounts
if(membership_level == "Gold", total * 0.85,
if(membership_level == "Silver", total * 0.9,
total))
Shipping Zones
if(country == "US", 5.99,
if(country == "Canada", 12.99,
25.99))
Multiple Calculations
Forms can have multiple calculated fields that reference each other:
// Field 1: Subtotal
quantity * unit_price
// Field 2: Tax
subtotal * 0.08
// Field 3: Total
subtotal + tax
Dependencies update in order, so "Total" automatically includes the latest tax calculation.
Error Handling
Division by Zero
if(denominator == 0, 0, numerator / denominator)
Invalid Numbers
Non-numeric inputs are treated as zero in calculations.
Missing Fields
If a referenced field doesn't exist, it's treated as zero.
Common Use Cases
Quote Calculators
Calculate project costs based on requirements:
base_cost + (hours * hourly_rate) + material_costs
Order Forms
Show running totals as customers shop:
sum_of_line_items + shipping + tax
Loan Calculators
Calculate monthly payments:
principal * (rate * pow(1 + rate, months)) / (pow(1 + rate, months) - 1)
Unit Converters
Convert between measurement systems:
feet * 0.3048 // Feet to meters
Best Practices
Clear Field Names
Use descriptive names that make formulas readable:
// Good
monthly_salary * 12
// Bad
field_1 * field_2
Test Edge Cases
Consider what happens with:
- Zero values
- Negative numbers
- Very large numbers
- Empty fields
Provide Context
Use help text to explain what's being calculated:
"Estimated monthly payment based on current rates"
Format Appropriately
Currency for money, percentages for rates, plain numbers for quantities.
Troubleshooting
Calculation Not Updating
- Check field name spelling (case-sensitive)
- Ensure referenced fields exist
- Verify formula syntax
Wrong Results
- Test with simple values first
- Check operator precedence (use parentheses)
- Verify field types (text vs number)
Performance Issues
- Complex formulas can slow form interaction
- Simplify calculations where possible
- Consider server-side calculations for heavy processing
NaN Results
"Not a Number" usually means:
- Invalid formula syntax
- Division by zero without protection
- Non-numeric input in calculation
Use browser developer tools to debug formula errors.