Repository navigation
The grid has decimal columns - #103
Merged
Merged
Conversation
A field can be "decimal" (Kind::Decimal): an exact decimal of up to 28 significant digits, for money and the like, as the engine already keeps. In the grid (Rust): - What is typed, pasted or filled into a decimal cell is read as a decimal (commas and underscores ignored); a bad one is refused by name. - A formula giving a decimal makes a decimal column. Formulas do not mix decimals and numbers, as in the engine: amount * 0.015d is a decimal, float(amount) * qty a number. - Totals are exact. Sum, average, minimum and maximum are kept by the graph as decimals; with a filter on, or for groups the graph is not asked to keep, the grid adds them up itself, exactly too. An average is the sum over the rows, to 28 digits. Totals are carried as Values, not f64s, so a decimal total reaches JSON as text. - Filters compare a decimal column against decimal bounds (=0.1 is 0.10) and sorting compares decimals exactly. - putMany's columns carry decimals as text, read and checked before any row is added. - A selection's stats and trend lines use the nearest f64. In JavaScript (@surefold/grid): - Kind gains "decimal", whose values are strings both ways (put and get), so nothing is rounded on the way; putMany takes a column of strings. - total() stays a number (the nearest, for a decimal column); totalExact() gives any total as text, exactly. groups() totals stay numbers. The same for a WorkerTable. - The grid formats a decimal from its text with Intl.NumberFormat, which formats a string exactly, so 12345678901234567.89 shows as it is; it aligns, filters, totals and flashes decimal columns as number columns. Tests: five Rust tests (exact totals where floats give 5.55e-17, reading typed decimals, formulas and the no-mixing rule, exact filters and sort, group totals and averages kept by the graph and added up by the grid, and putMany with a bad decimal adding no rows); four browser tests, with a Table and a WorkerTable (exact cells and totals as text; a 17-digit amount shown exactly; a typed decimal read exactly; filtering). All workspace tests and the 52 browser tests pass. Docs: the grid package README (decimals), the grid crate README's limits, watershed-core's README, limitations.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AdzBXcxXfE7iKtPMVoTTfr
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.
A grid field can now be
"decimal"(Kind::Decimal): an exact decimal of up to 28 significant digits, for money and the like, as the engine already keeps.0.10 + 0.20 − 0.30totals to0.00, not5.55e-17.Grid (Rust)
amount * 0.015dis a decimal,float(amount) * qtyis a number.Values rather thanf64s, so a decimal total reaches JSON as exact text.=0.1matches0.10.upsert_columnscarries decimals as text, and reads and checks them all before adding any row.f64.JavaScript (
@surefold/grid)Kindgains"decimal". Its values are strings both ways, forput/get/set/patch, so nothing is rounded on the way.putManytakes a column of strings.total()is unchanged: still a number, the nearest one for a decimal column.totalExact()is new and gives any total as exact text.groups()totals stay numbers. All of this is the same for aWorkerTable.Intl.NumberFormat, which formats a string exactly, so12345678901234567.89shows as it is. Decimal columns align, filter, total and flash like number columns.Tests
upsert_columnswith a bad decimal adding no rows.TableandWorkerTable):cargo test --workspace: 247 pass. Clippy andcargo docare clean. All 52 browser tests pass. Both grid demo apps type-check.Docs
limitations.md.Release
This adds to the grid packages' API (
"decimal",totalExact). Publishing it needs a version bump (0.6.0) and agrid-v0.6.0tag. I haven't bumped it here.Generated by Claude Code