Skip to content

More powerful number formatting #470

Closed

Description

@thomasp85

We currently rely on the sprintf crate for printf like formatting in the {:num ...} formatter. While it handles a lot it does not handle everything (e.g. thousand separator etc). While this is fine for now with only break values needing this, we may need stronger support when table support lands:

Two options:

  • numfmt: Arguably the largest feature addition, but using a formatting spec that is somewhat foreign to most.
  • format_num: Adds comma-only thousand separator with familiar (but slightly different - based on D3) printf syntax (minus % prefix). Also adds SI-unit and a bunch of other features (but fewer than numfmt)

Both are negligible in terms of binary size/compile time so a real option is to have both options available. Very little is lost by switching to format_num for the {:num ...} formatter and we could have auto detection of the format string to conditionally pass it to numfmt or format_num

Activity

  1. teunbrand commented on Jun 9, 2026

    @teunbrand
    Collaborator

    I'm afraid that if we go with format_num, we'll later discover a feature we want and we'd have to bit the formatting spec bullet anyway to go to numfmt. A 3rd option is to handroll a numeric formatter, which gives us a lot of control but is also a pain to maintain.

  2. thomasp85 commented on Jun 9, 2026

    @thomasp85
    CollaboratorAuthor

    well, my argument is that we can support both formats with a very little fallout in terms of binary size etc

  3. thomasp85 commented on Jun 9, 2026

    @thomasp85
    CollaboratorAuthor

    numfmt has poorer support for scientific notation (it just kicks in at certain thresholds) so I'm not super fond of that either...

    We should def not provide our own formatter I think

  4. teunbrand commented on Jun 9, 2026

    @teunbrand
    Collaborator

    Well I suppose either or both options are an improvement over the sprintf crate which advertises itself with the following:

    Note: You're probably better off using standard Rust string formatting instead of this crate unless you specificaly need printf compatibility.

  5. thomasp85 commented on Jun 12, 2026

    @thomasp85
    CollaboratorAuthor

    lol - it was chosen for that specific use case so we shouldn't read too much into that

  6. added
    plot buildingIn between the reader and writer, execution of plot logic
    on Jun 16, 2026
  7. thomasp85 commented on Nov 6, 2026

    @thomasp85
    CollaboratorAuthor

    This will be handled by zygos

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

    plot buildingIn between the reader and writer, execution of plot logic

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions