Skip to content

Should Amount's toString work like Number's? #47

@jessealama

Description

@jessealama

The toString() method for Numbers emits strings either in decimal or scientific notation, depending on how many digits are needed to express the value, thereby avoiding, in many cases, exposing an excessive number of digits.

Should Amount's toString do the same? In other words, should it use decimal notation for a small number of digits (for a definition of "small" that we can iterate on) and switch to exponential notation if there are a large number of digits to be displayed?

A related question is whether Amount, like Number, ought to have toExponential and toFixed methods that always emit strings in a certain format (exponential for the format, decimal for the latter)?

I would suggest that, if we want to follow the example of Number's toString(), that we should also have toExponential and toFixed for programmers to allow them to get output with a known syntax.

If one wanted to have just one method rather than three, perhaps we could have toString() take an options bag. One could have a format option with three possible values: auto (mimic Number's toString), decimal, and exponential.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions