Tomlyn icon indicating copy to clipboard operation
Tomlyn copied to clipboard

The decimal type is not serialized

Open tsadowski opened this issue 2 years ago • 3 comments

There is no toString method in TomlFormatHelper defined for the decimal floating point type. Decimal numbers are then simply missing from the output.

Reading numbers into a decimal type works.

Cheers, Torsten

tsadowski avatar Apr 26 '23 12:04 tsadowski

Toml (the spec) supports only binary64/double/f64 representable numbers. There's overlap between the numbers representable in binary64 and decimal, but both can express numbers that the other can't. This makes for a particularly challenging situation to implement, unless we were to use a string literal or something (which seems bad). I prototyped a solution that worked until the unit tests started testing decimal.MaxValue. It can't roundtrip, unfortunately.

lilith avatar Feb 01 '24 01:02 lilith

Here's my branch that explored this: https://github.com/lilith/Tomlyn/tree/decimal-support Honestly the safest approach might be to explicitly document decimal is not supported, and also throw an exception on use.

Reading numbers into a decimal type won't work if the double is too small or large.

lilith avatar Feb 01 '24 03:02 lilith

Honestly the safest approach might be to explicitly document decimal is not supported, and also throw an exception on use.

Yep, agreed. TOML was not meant for portable data but for easy configuration.

xoofx avatar Feb 01 '24 05:02 xoofx