Closed jessealama closed 2 months ago
Seems okay, though if we do this then the urgency of toString
returning the full data model (#12) is elevated, since developers will reach for toString
when serializing to JSON.
Of course, JSON.stringify
should convert decimals to string. I. e. if we have decimal embedded in some object, then JSON.stringify
should return something like {"foo":"0.1"}
. Because this is common practice to represent monetary decimals in REST APIs as strings
I would be slightly in favor, I think, of Decimal supporting toJSON, but if it does, it should retain the whole data model (trailing zeros) in order for it to round-trip.
As a first step in the integration between JSON and decimals, let's make decimal align with BigInts by throwing a
TypeError
.This decision isn't necessarily final. The change is made so that, at least, we have some kind of defined behavior. We may end up returning a value instead of throwing.
CC @sffc