generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Should Amount have a toJSON
method? If so, perhaps the method could return something like
{
"value": "123.456"
"unit": "kilogram"
}
The value in unit
could be undefined
if the Amount doesn't have a unit.
Do we want to include the significant digits and/or fraction digits properties, too?
This issue touches on #35. If we round on the way in, then the string contained in the value
property is precisely the value, so including significant digits and fraction digits is arguably unnecessary. However, if we round only on the way out (only), conversion to JSON might be like toNumber
, toString
in that toJSON
would not just emit a JSON object, but also do rounding beforehand. Altneratively, one could include significant digits and fraction digits in the JSON:
let a = new Amount(123.456);
a.with({ fractionDigits: 2 }.toJSON();
// { "value": "123.46", "unit": undefined }
// or:
// { "value": "123.456", "fractionDigits": 2, "unit": undefined }
Metadata
Metadata
Assignees
Labels
No labels