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 }
Should Amount have a
toJSONmethod? If so, perhaps the method could return something like{ "value": "123.456" "unit": "kilogram" }The value in
unitcould beundefinedif 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
valueproperty 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 liketoNumber,toStringin thattoJSONwould not just emit a JSON object, but also do rounding beforehand. Altneratively, one could include significant digits and fraction digits in the JSON: