Skip to content

A cookbook recipe: money with decimal columns - #104

Merged
matthewjones372 merged 1 commit into
mainfrom
claude/stoic-pascal-v0q6pz
Nov 16, 2026
Merged

matthewjones372 merged 1 commit into
mainfrom
claude/stoic-pascal-v0q6pz

Conversation

@matthewjones372

Copy link
Copy Markdown
Collaborator

This adds a cookbook recipe for #103's decimal columns: "Money with decimal columns", in both the Solid and React cookbooks.

The recipe

It's a café bill:

  • qty and price are "decimal" fields.
  • net = qty * price.
  • vat = round(net * 0.2d, 2): 20% to the cent, with ties going to the even cent.
  • gross = net + vat.
  • Each of these is totalled exactly.

A last column, float(gross), holds the same amount as an ordinary number. Its total comes to 23.159999999999997, where the bill's is €23.16. The bar above the grid shows both: the exact total from totalExact, formatted with Intl.NumberFormat (which formats the text exactly), and the ordinary numbers' total. You can edit a cell or use Add a cookie to watch both follow.

The notes cover:

  • the rule against mixing decimals and numbers (0.2d literals, float());
  • total against totalExact;
  • the 28-digit limit and the rounding functions;
  • how decimals go into put and putMany.

Other changes

  • tsconfig.base.json: adds ES2023.Intl to lib, which declares Intl.NumberFormat's format of a numeric string. Browsers have supported it since 2023, and it's type declarations only.
  • Cookbook pages: both pages' descriptions and intros mention the new recipe.

Tests

  • New browser test in each cookbook:
    • the bill comes to €23.16 while the numbers come to 23.159999999999997;
    • a typed quantity and an added line keep it to the cent;
    • every recipe still renders with no errors.
  • All 54 browser tests pass. The cookbooks, the demo apps, and the grid, React and Solid packages all type-check.

Generated by Claude Code

"Money with decimal columns", in Solid and React: a café's bill whose
quantities and prices are decimal fields, with net = qty * price, VAT as
round(net * 0.2d, 2) and gross = net + vat, each totalled exactly. A last
column, float(gross), is the same amount as an ordinary number: its total
comes to 23.159999999999997 where the bill's is 23.16. The bar shows the
exact total (totalExact, formatted with Intl.NumberFormat, which formats the
text exactly) beside the numbers' total. Edits and an Add a cookie button
show both follow.

The notes say the no-mixing rule (0.2d, float()), total against totalExact,
the 28 digits and the rounding functions, and how decimals go into put and
putMany.

tsconfig.base.json adds ES2023.Intl to lib, for Intl.NumberFormat's format
of a numeric string; browsers have had it since 2023.

A browser test per cookbook: the bill comes to 23.16 and the numbers to
23.159999999999997; a typed quantity and an added line keep it to the cent.
All 54 browser tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXcxXfE7iKtPMVoTTfr
@matthewjones372
matthewjones372 merged commit b568647 into main Nov 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants