Calculations and Namespaces Examples in Zolt
Basic Arithmetic
Simple mathematical operations:
- 15 # Addition: 15
- 12 # Subtraction: 12
- 12 # Multiplication: 12
- 5 # Division: 5
- 1 # Modulo: 1
Operator Precedence
Operators follow standard mathematical precedence:
- 13 # 13 (multiplication first)
- 25 # 25 (parentheses override)
- 512 # 512 (right associative: 2(32))
Power Operator
Using the ^ operator:
- 256 # 256
- 100 # 100
- 27 # 27
- 1 # 1
Math Namespace
Rounding Functions
Absolute Value
Min/Max
Power and Square Root
- 256 # 256
- 1000 # 1000
- 4 # 4
- 1.4142135624 # 1.41...
List Namespace
List Operations
Aggregation
- 150 # 150
- 30 # 30
- 5 # 5 (alias of length)
String Namespace
Case Conversion
- HELLO # "HELLO"
- hello # "hello"
String Operations
- 4 # 4
- text # "text"
- herro # "herro"
String Split
- ["apple","banana","cherry"] # ["apple", "banana", "cherry"]
Practical Examples
- Subtotal: 89.97 # 89,97
- Tax: 7.1976 # 7,1976
- Total: 97.1676 # 97,1676
Statistics
- Average: 88 # 88
- Highest: 95 # 95
- Lowest: 78 # 78
- Sum: 438 # 438
Temperature Conversion
- Fahrenheit: 77°F # 77
- Kelvin: 298.15K # 298,15
Financial Calculations
- Simple Interest: 150 # 150
- Total Amount: 1150 # 1150
Compound Interest
- Amount: 1161.4722313335 # 1161.47
Percentage Calculations
- Percentage: 30% # 30%
- Rounded: 30% # 30%
Grade Calculation
Area Calculations
- Circle Area: 78.53975 # 78.54
- Circumference: 31.4159 # 31.42
Rectangle
- Area: 50 # 50
- Perimeter: 30 # 30
Budget Planning
- Total Expenses: 2700 # 2700
- Remaining: 2300 # 2300
- Savings Rate: 46% # 46%
Data Analysis
- Total Sales: 8000 # 8000
- Average: 1600 # 1600
- Growth: 62.5% # 62.5%
Scientific Calculations
- Kinetic Energy: 12500J # 12500J
- Work Done: 500J # 500J
Complex Examples
Invoice Calculation
- Widget: 5 × 19.99 = 99.95
- Gadget: 3 × 29.99 = 89.97
- Tool: 2 × 49.99 = 99.98
- Subtotal: 289.9 # 289.90
- Tax (8%): 23.192 # 23.19
- Total: 313.092 # 313.09
Loan Calculator
- Monthly Payment: 1013.3706196518 # 1013.37
BMI Calculator
- BMI: 22.8571428571 # 22.86
- Category:
Normal weight # Normal weight
Use Cases
- Total Time: 2.5 # 2.5
- Server: 12% # 12%
- Render: 88% # 88%
Time Calculations
Discount Calculator
- Discount: 20 # 20
- Sale Price: 80 # 80
Tip Calculator
- Tip: 15.39 # 15.39
- Total: 100.89 # 100.89
Unit Conversion
- Miles: 62.1371 # 62.14
- Meters: 100000 # 100000
- Feet: 328084 # 328084
Currency Conversion
Scientific Notation
- 123000 # 123000
- 0.00123 # 0.00123
- 300 # 300
Best Practices
Precision
Validation
Cannot divide by zero
Readability
$subtotal = $quantity * $unit_price
$total = $subtotal * (1 + $tax_rate)
Better than:
$total = $quantity * $unit_price * (1 + $tax_rate) }}
← Back to Examples Index