Build a Quote Calculator With AI: A Worked Example
A quote calculator is mostly a pricing rulebook with a form on top. Keep the rules as data and the maths in one tested function, and the AI has little room to get it wrong.
To build a quote calculator with AI, separate the pricing rules from the code that applies them. Store the rates and multipliers as plain data, write one pure function that turns a job description into a price, keep all money in whole cents, and ask the AI for the form and the tests separately. The arithmetic stays in one place you can check.
Quote tools tempt people to let the model write everything in one go, including the maths scattered through the interface code. That is how a calculator ends up charging 0.30000000000000004 of something. The worked example below is a painter's quote, but the structure fits any trade that prices by area, time or quantity.
Build the quote calculator: write the rulebook before any code
Open a document and write down how you really price a job. For the example, a painter charges:
A rate per square metre of wall and of ceiling, and per metre of trim.
A multiplier for the number of coats: more coats cost more, but not in proportion, since setup is shared.
A multiplier for prep: none, light or heavy.
A fixed call-out fee.
A minimum charge for small jobs.
Sales tax on top.
If you cannot state these rules clearly, the AI cannot invent them for you. A model asked to "build a quote calculator for a painter" will make up plausible rates, and you will not notice until a customer holds you to one. Everything the calculator knows must come from you.
Step 2: Put the rules in data, not code
const RULES = {
currency: "CHF",
minimumCents: 25000,
rates: { wallPerSqmCents: 1400, ceilingPerSqmCents: 1100, trimPerMetreCents: 450 },
coatMultiplier: { 1: 1.0, 2: 1.7, 3: 2.3 },
prep: { none: 1.0, light: 1.15, heavy: 1.4 },
callOutCents: 6000,
vatRate: 0.081
};The numbers are examples for the demonstration, including the tax rate, so put in your own and your region's current rate. Prices change, and a change should mean editing this object, not hunting through interface code. It is also the one block you review line by line against your own rate card.
Step 3: One pure function does all the maths
function quote(job, rules = RULES) {
const r = rules.rates;
const base = job.wallSqm * r.wallPerSqmCents
+ job.ceilingSqm * r.ceilingPerSqmCents
+ job.trimMetres * r.trimPerMetreCents;
const coats = rules.coatMultiplier[job.coats];
const prep = rules.prep[job.prep];
if (coats === undefined || prep === undefined) {
throw new Error("Unknown coats or prep value");
}
const labour = Math.round(base * coats * prep);
const subtotal = Math.max(labour + rules.callOutCents, rules.minimumCents);
const vat = Math.round(subtotal * rules.vatRate);
return { labour, subtotal, vat, total: subtotal + vat };
}Three decisions in that function are the ones AI-written calculators most often get wrong.
Whole cents. All amounts are integers in cents. JavaScript numbers are, per the MDN documentation, double-precision 64-bit binary floating point values, like decimals in most languages, where 0.1 + 0.2 gives 0.30000000000000004. Integers do not drift. You round exactly once per step, with Math.round, and convert to a display string only at the very end. Handling money in an AI-built app goes deeper on why.
Unknown input throws. If the form sends coats: 5, the function raises an error instead of quietly pricing it as undefined, which would produce NaN on a customer's screen.
The minimum applies after the call-out. Math.max means a small job never quotes below the minimum charge. Where the minimum sits relative to other fees is a business decision, so check that the order matches how you actually charge.
Step 4: Check it with two jobs you can verify by hand
Running the function on a living room (42 square metres of wall, 14 of ceiling, 18 metres of trim, two coats, light prep) gives:
Step | Cents | Amount |
|---|---|---|
Base: 42 x 1400 + 14 x 1100 + 18 x 450 | 82,300 | 823.00 |
After coats (x1.7) and prep (x1.15) | 160,897 | 1,608.97 |
Plus call-out 6,000 | 166,897 | 1,668.97 |
Tax at 8.1% | 13,519 | 135.19 |
Total | 180,416 | 1,804.16 |
And a small job: 6 square metres of wall, 2 metres of trim, one coat, no prep. The labour comes to 93.00, plus the call-out is 153.00, which is below the 250.00 minimum, so the subtotal becomes 250.00, tax is 20.25 and the total is 270.25.
Work the first one out on paper before you trust the code. If your hand total and the function disagree, one of them is wrong, and it is better to find out now.
Step 5: Ask the AI for the form and the tests, not the maths
Split your requests. The model is good at interface code and at writing test cases. Keep it away from deciding prices.
Here is a function quote(job, rules) and a RULES object. Do not change
either of them.
1. Build a form with number fields for wall area, ceiling area and trim
length, a select for coats (1, 2, 3) and prep (none, light, heavy).
2. On every change, call quote() and show the result as currency, with
the division by 100 done only in the display layer.
3. Validate inputs: no negatives, no empty fields, numbers only.
Show a message instead of calling quote() when invalid.
4. Write unit tests using these two jobs and expected totals:
<paste the two cases from Step 4>
plus tests for: zero area, unknown coats value, and the minimum charge.The tests are your contract. Using AI to write tests that catch bugs explains how to review them so they check real behavior and not just that the code runs. Once the calculator works, a customer will usually want a copy, and adding a print invoice feature is a natural next step.
What to put in the interface
Show the working, not just the total: labour, call-out, tax. Customers trust a number they can follow. Add a line saying the figure is an estimate and what could change it. If quotes feed into your sales process, a simple CRM built with AI can store them against the customer. For the writing side, see using AI to write customer quotes.
If this is your first build, the complete guide to building an app with AI covers the surrounding steps.
FAQ
Can AI build a quote calculator for me?
Yes, for the interface and tests. The pricing rules and the arithmetic should come from you and live in one function and one data object that you check by hand.
Why store money as cents instead of decimals?
Decimal numbers in most languages use binary floating point, which cannot represent values like 0.1 exactly. Whole-number cents avoid rounding drift.
Where should the tax calculation go?
In the same pure function as the rest of the maths, using a rate stored in your rules. Check the rate and rounding rules for your region, since they vary.
How do I stop the calculator giving a wrong price?
Keep the rules in one reviewed object, reject invalid inputs, and cover your own real past jobs with tests so any change that shifts a known price fails loudly.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


