-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Current Behavior
The current design is incoherent in its interpretation and usage of fractionDigits and significantDigits, especially in the places where it computes those from provided values. Some examples:
| Input value | computed fractionDigits | computed significantDigits | Output value |
|---|---|---|---|
| 120 | 0 | 3 | "120" |
| "1.20e2" | 2 | 3 | "120.00" |
| "1.410e15" | 3 | 4 | "1410000000000000.000" |
| "0.05" | 2 | 3 | "0.05" |
| ".05" | 2 | 2 | "0.05" |
| "5e-2" | 0 | 1 | "0" |
| 0 | 0 | 1 | "0" |
| "000.00" | 2 | 5 | "0.00" |
| "0.00" | 2 | 3 | "0.00" |
| ".00" | 2 | 2 | "0.00" |
| "00e-2" | 0 | 2 | "0" |
The computed significantDigits is never used in the spec and has no effect on the output. The computed fractionDigits specifies the number of digits to output after the decimal point, which sometimes results in incorrect output, as seen in the table above.
Corrected Behavior
I propose that we adopt the mathematical definition of fractionDigits to be the power of 10 of the least significant precise digit of the value. This works for both zero and nonzero values:
| Input value | mathematical fractionDigits |
|---|---|
| 0 | 0 |
| "0.0000" | 4 |
| ".0000" | 4 |
| "0e-3" | 3 |
| "1245.000" | 3 |
| 120 | 0 |
| "120.0" | 1 |
| "00120" | 0 |
| "0.05" | 2 |
| ".05" | 2 |
| "5e-2" | 2 |
| "5.0e-2" | 3 |
| "1.23e3" | -1 |
| "1.410e15" | -12 |
Negative fractionDigits are required if we want to faithfully store the precision of numbers in exponential notation. Thus, if we include exponential notation as part of the resolution of issue #52, then we must allow and process negative fractionDigits.
significantDigits
Since it's never used, I propose that significantDigits not be computed.
On the other hand, the explainer provides a method to read significantDigits of Amounts. That method is not in the spec, and I assume the spec is correct here. If we wish to introduce such a method, we should define significantDigits in terms of fractionDigits as follows:
If
| Input value | computed fractionDigits | computed significantDigits |
|---|---|---|
| 0 | 0 | degenerate |
| "0.0000" | 4 | degenerate |
| ".0000" | 4 | degenerate |
| "0e-3" | 3 | degenerate |
| "1245.000" | 3 | 7 |
| 120 | 0 | 3 |
| "120.0" | 1 | 4 |
| "00120" | 0 | 3 |
| "0.05" | 2 | 1 |
| ".05" | 2 | 1 |
| "5e-2" | 2 | 1 |
| "5.0e-2" | 3 | 2 |
| "1.23e3" | -1 | 3 |
| "1.410e15" | -12 | 4 |
Unfortunately significantDigits becomes degenerate if
Infinities and NaN
fractionDigits and significantDigits have no effect on infinities and NaN, so we should ignore them if provided as options on input.