Skip to content

bug(shopping): prices render with float-precision garbage  #417

Closed

Description

@gkhngyk

Problem

On /dashboard/shopping, product prices render with raw float-precision garbage, e.g. 2999.989990234375 TRY in the Competitors products table.

Two layers contribute:

  1. Source data carries float32 noise. Cloro's Copilot responses serialize prices like 2999.989990234375 (= float32 of 2999.99) and 2999.39990234375 (= 2999.40). The card normalizer (server/src/lib/shopping-cards.js, parsePrice) stores the amount as-is, so the noise lands in prompt_result_shopping_cards.price_amount.
  2. The UI does no money formatting. web/src/app/[locale]/(dashboard)/dashboard/shopping/page.tsx renders the raw value — {p.last_price} {p.price_currency} (~line 1146) and {card.price} in the appearances drawer (~line 705). The CSV export uses the same raw value.

Fix (both layers)

  1. Normalize: in parsePrice, round the parsed amount to 2 decimals (Math.round(amount * 100) / 100) so the noise is cut at the source. Add a test case with a float32-noisy input (e.g. 2999.989990234375 → 2999.99).
  2. Display: format prices in the Shopping UI with Intl.NumberFormat (2 fraction digits, thousands separators) wherever price_amount/last_price is shown — product tables, the appearances drawer, and the CSV export can keep the plain 2-decimal number.

Cleanup of existing rows

Existing prompt_result_shopping_cards rows keep the noisy values until re-normalized. The backfill script (server/src/scripts/backfill-shopping-cards.js) is idempotent and re-derives from the raw cards on prompt_results, so one run after the parser change rewrites history — no migration needed. (Ops note: a backfill run is already planned for #399's ChatGPT cards; doing it after this lands cleans both in one pass.)

Acceptance criteria

  • parsePrice rounds amounts to 2 decimals (unit test with a float32-noisy input)
  • Shopping tables/drawer display formatted prices (no …989990234375 anywhere)
  • CSV export emits at most 2 decimals
  • Backfill run re-normalizes existing rows (verified on a brand with Copilot cards)

Activity

  1. added
    bug
    good first issue
    on Jul 12, 2026
  2. changed the title [-]bug(shopping): prices render with float-precision garbage (e.g. 2999.989990234375 TRY)[/-] [+]bug(shopping): prices render with float-precision garbage [/+] on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions