Migrating Bubble Calculations: Preserve Prices, Rounding and Totals
A rebuilt Bubble app can show the same quote screen and still produce a different price. A discount may move to another step, a percentage may change scale, or an amount may be rounded before it reaches the payment provider. The screen looks familiar; the customer receives a different total.
When migrating a Bubble.io app to code, treat calculation behavior as a contract—not a formula to copy from a screenshot. Preserve the inputs, operation order, rounding rules and historical values that determine what a customer actually accepts or pays. Then prove the replacement against concrete examples.
Start with the transaction, not the dashboard
Choose one consequential workflow: generating a quote, applying a discount, calculating a commission, or preparing a payment amount. Follow it from the user’s input to the saved record and any external request. Include backend workflows, conditions, plugins and API responses that can alter the result.
This is different from checking whether a dashboard sums existing orders correctly. Here, the question is how each order amount was created. A correct aggregate cannot rescue incorrectly calculated transactions. Pair this work with the Bubble data migration checklist so that price inputs and relationships survive the move.
For each workflow, collect a few approved examples and record the raw inputs, intermediate results, saved amount, displayed amount and outbound payload. Use anonymized fixtures rather than customer records in a public specification. If the current behavior is inconsistent, log the discrepancy and get a decision; do not silently classify it as either a requirement or a bug.
Write a calculation contract before choosing a number type
A useful contract answers six questions. It should be short enough for the product owner to review and precise enough for an engineer to turn into automated tests.
- Inputs and units: Is a rate stored as 10 or 0.10 for ten percent? Is a quantity an integer, hours with fractions, or a measured amount? Which currency accompanies the number? Are blank, zero and missing values distinct?
- Operation order: Does the discount apply before or after another charge? Is a fixed fee included in the discount base? Are quantity breaks evaluated before or after combining lines? Record the actual sequence, including conditions.
- Precision and rounding: At which steps is rounding applied, to what scale, and using which midpoint rule? Are positive and negative amounts treated consistently? Keep high-precision unit rates separate from the final payable amount where the business rules require that.
- Stored and displayed values: Which amount is authoritative? Is the interface merely formatting it, or is formatted text being parsed back into a later calculation? A currency label with two decimal places does not establish the precision of the saved value.
- External boundaries: What units and representation does each API expect? Define conversions once at those boundaries. Do not allow the browser, server and integration code to make independent rounding decisions.
- Historical behavior: Which prices, rates and calculation version belong to an accepted transaction? Specify whether reopening a draft recalculates it, while an accepted quote or completed order retains its original snapshot.
These requirements describe application behavior, not a universal tax or accounting policy. Where business or regulatory rules determine the calculation, have the responsible owner approve the rule rather than copying an illustrative formula.
Separate Bubble’s operators from your business rules
Bubble documents :rounded to as decimal-place rounding, while :formatted as produces text. Its number documentation also describes final mathematical output being rounded to 15 significant figures before display or conversion to a non-number type. None of these details establishes your app’s required currency scale, midpoint handling or order of operations.
Inspect the actual expressions and test boundary values in the existing app. Do not infer negative midpoint behavior from a positive example. Also find conversions from formatted text back to numbers: decimal and thousands separators can turn a locale-dependent display choice into a calculation input. The Bubble operations reference is a useful map of the operators, but the migration fixtures must establish your app’s behavior.
Use a small fixture that exposes the rounding decision
Consider a fictional USD quote with three separate lines. Each line has quantity 1 and a unit price of 0.05. A 10% discount applies, with no other charges. For this example only, the agreed rule is exact decimal arithmetic, round each discounted line to two decimal places using half-up rounding, then sum the lines.
Per line: 0.05 × (1 − 0.10) = 0.045, rounded to 0.05. Three lines therefore total 0.15. If a replacement instead discounts the combined 0.15 and rounds only once, it calculates 0.135, rounded to 0.14. Both implementations look reasonable; only one follows the example’s contract.
Store the fixture with decimal input strings, currency USD, percentage convention 0.10, the three line identifiers, operation order, rounding stage, rounding mode and calculation version. Expected outputs are three saved line amounts of 0.05, a saved total of 0.15, a display such as $0.15, and a serialization-only USD Stripe example of 15 minor units. This is not a valid charge example: provider minimum amounts are a separate constraint.
This is an invented test, not a claim about Bubble’s default policy or a recommendation for your product. Replace it with your approved rules. Add cases for a zero discount, a maximum allowed quantity, a fractional quantity, a price with more precision than the payable amount, and a negative adjustment if the product supports one. Test values immediately below, at and above a rounding boundary.
For final monetary values, compare the agreed canonical amount exactly. Do not add a broad numerical tolerance merely to hide unexplained differences. If a non-monetary measurement needs a tolerance, document that separately from the payable total.
Keep precision intact across storage and code
JavaScript Number uses binary floating-point arithmetic. Decimal fractions are not all represented exactly, so replacing a Bubble expression with ordinary arithmetic and a final toFixed call is not, by itself, a monetary calculation design. Formatting a result does not repair an earlier change in operation order.
For exact decimal calculations, use an appropriate decimal implementation and preserve decimal values at serialization boundaries. For finalized amounts represented in integer minor units, still define how division, percentages and fractional quantities are rounded. Check supported ranges as well: JavaScript integers are not all exactly representable beyond Number.MAX_SAFE_INTEGER. Neither approach removes the need for a contract.
PostgreSQL numeric can represent decimal values exactly, but a declared column scale can round a value when it is stored. Its documented numeric midpoint behavior also matters if rounding is delegated to the database. Choose a scale that fits the domain; a two-decimal column may be suitable for one finalized amount and unsuitable for a high-precision unit rate.
Follow a value through the complete path: input parsing, calculation, persistence, API serialization and display. A decimal-safe database does not protect a value that is converted into an unsuitable numeric representation before the next operation. Use the JavaScript Number reference and PostgreSQL numeric documentation to make these choices explicit.
Verify API units without changing payment behavior
Payment providers define their own amount formats. Stripe generally expects amounts in the currency’s minor unit: USD 10 is represented as 1000, while JPY 10 is represented as 10. Currency-specific exceptions exist, so “multiply every amount by 100” is not a safe conversion rule. Check the supported-currency documentation for the exact operation you use.
Test the outgoing amount, currency and returned result in a non-production environment. Keep this separate from any change to subscriptions, payment collection or refunds. If the migration also moves those workflows, use the Stripe continuity guide and API migration guide alongside the calculation tests; arithmetic parity does not prove the rest of the payment integration is correct.
Protect accepted prices from a new calculation engine
Importing an old quote and recalculating it with today’s catalog can change what the customer accepted. Preserve the original unit prices, quantities, discounts, currency and finalized amounts where those are part of the transaction record. Keep the applicable rule or rate version when the product needs to explain how the price was produced.
Separate historical snapshots from editable drafts. Define exactly which user action can trigger a new calculation and whether it creates a new version. If legacy records lack sufficient inputs to reproduce a total, retain the known result and flag the missing provenance rather than inventing a reconstruction.
If you discover an old calculation defect, treat remediation as an explicit product decision with its own affected-record review. A migration should not quietly rewrite accepted amounts under the label of improved precision.
Make calculation parity a release decision
Run the same approved fixtures through the existing app and replacement without triggering real charges or sending customer documents. Compare intermediate steps as well as final outputs. Classify each difference: input conversion, rule order, rounding stage, storage scale, historical data or API unit conversion. This makes a one-cent mismatch diagnosable instead of merely visible.
Keep the fixtures in the automated test suite. Before cutover, obtain approval for any intentional behavior change and confirm that no unexplained differences remain in the agreed release cases. The test set cannot cover every future input, so enforce documented input limits and monitor calculation failures after launch.
Frequently asked questions
- Should every monetary field use two decimal places?
- No. Currency rules, fractional quantities and unit-rate precision can differ. Separate intermediate calculation precision from the final amount’s required scale, and check each external system’s contract.
- Can we simply keep the total that Bubble displays?
- A display is useful evidence, but it is not the full calculation. Compare the saved value and external payload too. Formatting can conceal extra precision, and a later workflow may recalculate the amount.
- Should a rebuild fix existing rounding differences?
- Only as an explicitly approved behavior change. First establish which outcomes are required and which are defects. Preserve historical accepted amounts unless there is a separate, authorized correction process.
Sources
- 01Bubble operations reference · Bubble Docs
- 02JavaScript Number reference · MDN Web Docs
- 03PostgreSQL numeric documentation · PostgreSQL Docs
- 04supported-currency documentation · Stripe Docs
Keep reading
Bubble to Code is an independent service. Not affiliated with, endorsed by, or sponsored by Bubble Group, Inc.
