Skip to content

The grid has decimal columns - #103

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

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.30 totals to 0.00, not 5.55e-17.

Grid (Rust)

  • Input: what's typed, pasted or filled into a decimal cell is read as a decimal (commas and underscores are ignored). A bad value is refused by name.
  • Formulas: a formula that gives a decimal makes a decimal column. As in the engine, formulas don't mix decimals and numbers: amount * 0.015d is a decimal, float(amount) * qty is 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 isn't asked to keep, the grid adds them up itself, also exactly.
    • An average is the sum divided by the rows, to 28 digits.
    • Totals are now carried as Values rather than f64s, so a decimal total reaches JSON as exact text.
  • Filters and sorting compare decimals exactly. A filter's bounds are read as decimals, so =0.1 matches 0.10.
  • upsert_columns carries decimals as text, and reads and checks them all before adding any row.
  • Approximations: a selection's stats and trend lines use the nearest f64.

JavaScript (@surefold/grid)

  • Kind gains "decimal". Its values are strings both ways, for put/get/set/patch, so nothing is rounded on the way. putMany takes 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 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. Decimal columns align, filter, total and flash like number columns.

Tests

  • Rust (5 new):
    • exact totals;
    • reading typed decimals;
    • formulas, and the rule against mixing decimals and numbers;
    • exact filters and sorting;
    • group totals and averages, both kept by the graph and added up by the grid;
    • upsert_columns with a bad decimal adding no rows.
  • Browser (4 new, Table and WorkerTable):
    • exact cells and totals as text;
    • a 17-digit amount shown exactly in the grid and in its total row;
    • a typed decimal read exactly;
    • filtering.
  • Everything else: cargo test --workspace: 247 pass. Clippy and cargo doc are clean. All 52 browser tests pass. Both grid demo apps type-check.

Docs

  • The grid package README has a new "Decimals" section.
  • The grid crate README's limits.
  • watershed-core's README.
  • limitations.md.

Release

This adds to the grid packages' API ("decimal", totalExact). Publishing it needs a version bump (0.6.0) and a grid-v0.6.0 tag. I haven't bumped it here.


Generated by Claude Code

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
@matthewjones372
matthewjones372 merged commit f673d8f into main Nov 16, 2026
9 checks passed
@matthewjones372
matthewjones372 deleted the claude/stoic-pascal-v0q6pz branch November 16, 2026 22:11
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