Repository navigation
A cookbook recipe: money with decimal columns - #104
Merged
Merged
Conversation
"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
pushed a commit
that referenced
this pull request
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
qtyandpriceare"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.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 fromtotalExact, formatted withIntl.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:
0.2dliterals,float());totalagainsttotalExact;putandputMany.Other changes
tsconfig.base.json: addsES2023.Intltolib, which declaresIntl.NumberFormat'sformatof a numeric string. Browsers have supported it since 2023, and it's type declarations only.Tests
Generated by Claude Code