Skip to content

How should my app test fractional credits across JSON, database storage and reports?

Choose an exact representation for credits in your application's persistence and accounting logic, then test round trips from API decoding through storage and reporting. AISwapLab documents millionth-credit increments. Binary floating-point arithmetic can introduce residuals, so an apparently correct UI value is not sufficient validation.

TEST THE CUSTOMER API CONTRACTAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Define one internal unit; Round-trip boundary values; Separate display from accounting.
Workflow diagram: Define one internal unit → Round-trip boundary values → Separate display from accounting. Read the article for evidence and limits.

Precision can be lost between layers

A decoder, ORM, database column and report exporter may each choose different numeric types. Repeated conversion can produce a ledger that fails to reconcile even when every individual display rounds to a plausible number. Test the full path rather than one helper function.

What to do next

  1. 01

    Define one internal unit

    Use an exact decimal type or integer millionth-credit units within supported ranges. Document where conversion from JSON numbers occurs and reject values outside the reviewed precision rather than silently rounding them at unrelated layers.

  2. 02

    Round-trip boundary values

    Test the smallest supported increment, mixed whole and fractional amounts, and the application's maximum permitted amounts. Persist, reload, aggregate and export them, checking exact values before applying any presentation formatting.

  3. 03

    Separate display from accounting

    Format readable numbers only at the final display boundary. Keep the exact stored units available for reconciliation and avoid recomputing historical charges from a rounded price shown on an earlier screen.

A concrete example

Illustrative example: three fixture receipts contain 0.000001, 0.125 and 2 credits. Their stored internal units sum exactly before formatting. Exporting and importing the report preserves that sum rather than depending on rounded text.

Before you call it ready

  • Database columns preserve required precision.
  • Aggregation uses exact internal units.
  • Formatting never changes stored accounting values.

A locally executed, reproducible check

Binary float addition differs from decimal addition; serialized integer units round-trip exactly in this fixture.

We executed this exact synthetic fixture on November 16, 2026 with Python 3.12.10 and SQLite 3.49.1. It ran locally with no network requests, account data or model generation. The recorded output below is an observation from that environment, not a platform benchmark. Copy the code into a separate Python file to repeat it in a suitable local environment; compare the mechanism and check your runtime version.

python
from decimal import Decimal
import json
print('binary float:',0.1+0.2)
print('decimal:',Decimal('0.1')+Decimal('0.2'))
units=[1,125000,2000000]
restored=json.loads(json.dumps({'credit_microunits':units}))
print('restored total units:',sum(restored['credit_microunits']))
print('restored total credits:',Decimal(sum(restored['credit_microunits']))/Decimal(1000000))

Recorded output and interpretation

Microunits are an illustrative internal representation, not a new AISwapLab billing denomination. Verify the actual field’s published precision and historical credit version; these calculations do not establish prices or refund rights.

A matching local output establishes only the illustrated library or database behavior under these inputs. It does not certify a production integration. Preserve the approved action, authorization boundaries and current AISwapLab request contract when applying the idea.

text
binary float: 0.30000000000000004
decimal: 0.3
restored total units: 2125001
restored total credits: 2.125001

When to stop or choose another method

Stop reconciling application charges from rounded UI strings or repeated floating-point conversions when exact credit units are available.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation