Docs  /  Pricing & Rules  /  Price Formulas & JavaScript Calculations

Price Formulas & JavaScript Calculations

Last updated: 01. January 2026

With formulas you can implement complex price calculations that go beyond simple surcharges. Formulas access the values and surcharges of all features and calculate a price from them in real time.

For standard cases, simple formula expressions are enough. For very complex logic, full JavaScript code is also available.

Where Are Formulas Stored?

Formulas are stored in the price settings of an option, or directly as a formula price rule at component level. You can use formulas for individual options or as a total price formula.

Simple Formulas

Referencing Feature Values

[feature_name]          → numeric value of the feature (for free input)
[feature_name.price]    → surcharge of the selected option
[_base_price]           → base price of the component

Basic Operators

+   Addition
-   Subtraction
*   Multiplication
/   Division
^   Power
()  Brackets for order of operations

Functions

ROUND(value, digits)    → round to n decimal places
CEIL(value)             → round up to whole number
FLOOR(value)            → round down to whole number
MAX(a, b)               → larger of the two values
MIN(a, b)               → smaller of the two values
IF(condition, a, b)     → if condition true → a, else → b
ABS(value)              → absolute value (without sign)

Practical Examples

Area price (width × height):

[width] * [height] * 0.025

Area price with minimum price:

MAX([width] * [height] * 0.025, 49.00)

Rounded metre price:

CEIL([length] / 100) * 12.50

Tiered price (quantity discount):

IF([quantity] >= 100, [quantity] * 8.90,
  IF([quantity] >= 50, [quantity] * 9.50,
    [quantity] * 10.90))

Combination of area and surcharges:

([width] * [height] * 0.020) + [colour.price] + [drive.price]

Advanced Calculations with JavaScript

When the simple formula syntax is not sufficient, you can store full JavaScript code. This allows arbitrarily complex calculation logic — loops, arrays, external lookups, custom algorithms.

Basic Structure

The JavaScript code must return a numeric value at the end:

// All feature values are available as variables
var area = width * height;
var base_price = area * 0.025;

// Minimum price
if (base_price < 49) {
    base_price = 49;
}

// Return value
base_price;

Feature Values in JavaScript

All features are available as JavaScript variables — named after their internal name:

// Numeric values directly
width           // value of the "width" feature
height          // value of the "height" feature
quantity        // value of the "quantity" feature

// Surcharges of the selected option
colour_price    // surcharge of the selected colour
drive_price     // surcharge of the selected drive

// Base price
_base_price     // base price of the component

Practical Examples

Complex tiered price with table:

var tiers = [
    { from: 1,   price: 10.90 },
    { from: 10,  price: 9.50 },
    { from: 50,  price: 8.90 },
    { from: 100, price: 7.90 },
    { from: 500, price: 6.90 }
];

var unit_price = tiers[0].price;
for (var i = 0; i < tiers.length; i++) {
    if (quantity >= tiers[i].from) {
        unit_price = tiers[i].price;
    }
}

quantity * unit_price;

Price calculation with surcharges depending on the combination:

var base = width * height * 0.022;

// Material surcharge
var materialFactor = 1.0;
if (material === 'stainless') materialFactor = 1.35;
if (material === 'wood')      materialFactor = 1.20;

// Express surcharge
var express = (delivery_time === 'express') ? base * 0.25 : 0;

// Minimum price
Math.max(base * materialFactor + express, 59.00);

Price calculation with industry-standard rounding rules:

// Area in m² (input in cm)
var area_m2 = (width / 100) * (height / 100);

// Round up to 0.1 m² (minimum order quantity)
var area_rounded = Math.ceil(area_m2 * 10) / 10;

// Price from price zone
var price_per_m2 = 45.00;
if (area_rounded > 5)  price_per_m2 = 42.00;
if (area_rounded > 10) price_per_m2 = 38.00;

area_rounded * price_per_m2 + drive_price;

Available JavaScript APIs

Standard JavaScript objects are available in the formula context:

Math.round(), Math.ceil(), Math.floor()
Math.min(), Math.max(), Math.abs()
Math.pow(), Math.sqrt()
parseInt(), parseFloat()
Array, Object, JSON

No access to the DOM, external HTTP requests or browser APIs — the calculation runs server-side.

Testing Formulas

In the backend, the preview immediately shows the result for different input values. Enter test values and check whether the calculation is correct.

AI Agent for Formulas and JavaScript

The AI agent can create both simple formulas and complex JavaScript code:

"The price should be width times height times 0.025 euros, but at least 49 euros."

"I need a tiered price: up to 10 units €10.90, from 10 units €9.50, from 50 units €8.90, from 100 units €7.90."

"The price should be rounded up to full 0.1 m² and become cheaper per m² for larger areas."

The agent writes the code and stores it directly in the component.

Troubleshooting

Formula returns 0 or NaN:

  • Check the feature names — mind upper and lower case
  • Make sure the referenced feature is a numeric field
  • Check the JavaScript syntax for errors (missing semicolons, brackets)

JavaScript does not return a value:

  • Make sure a numeric expression comes last (no return, no console.log)
  • Check for undefined or null in conditional logic

Unexpected values:

  • Mind the units (mm vs. cm vs. m)
  • console.log() for troubleshooting — output appears in the browser console of the preview

Next Steps


← All articles Try free for 14 days