Skip to content

[stdlib] Add an option for thousands separator to package "format" #186

@trs123

Description

@trs123

The primitive Format from stdlib's package "format" should allow for formatting with thousands separators, e.g. "10,000,000" instead of "10000000".

Note
Of course the thousands separator should be language dependent (and I just learned that even the grouping is language/culture dependent) but i18n seems not supported yet by Pony. I assume that currently the package "format" uses "." as decimal separator and therefore could use "," as grouping separator with a grouping of 3 digits for now (thousands separator). To allow more freedom the thousands separator to be used could be provided instead.

Proposal
The basic function Format.apply() could by extended with a new parameter separator (or maybe sep as Pony APIs seem to prefer abbreviated variable names):

"""
...
* sep. The character to be used as thousands separator.
"""
fun apply(
    str: String,
    fmt: FormatDefault = FormatDefault,
    prefix: PrefixDefault = PrefixDefault,
    prec: USize = -1,
    width: USize = 0,
    align: Align = AlignLeft,
    fill: U32 = ' ',
    sep: (U32 | None) = None)
    : String iso^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions