-
Notifications
You must be signed in to change notification settings - Fork 5
Description
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
.