Skip to content

Keep decimal precision when reading through the schema - #182

Open
vtxe02023274 wants to merge 1 commit into
xoofx:mainfrom
vtxe02023274:fix-schema-decimal-precision
Open

vtxe02023274 wants to merge 1 commit into
xoofx:mainfrom
vtxe02023274:fix-schema-decimal-precision

Conversation

@vtxe02023274

Copy link
Copy Markdown

With UseSchema = true, YamlScalar.TryParseDecimal(YamlReader, ...) takes the value the schema resolved. For a float that value is a double, so a decimal member only keeps about 15 significant digits:

var options = new YamlSerializerOptions { UseSchema = true };
YamlSerializer.Deserialize<decimal>("1234567890.123456789", options); // 1234567890.12346
YamlSerializer.Deserialize<decimal>("1234567890.123456789");          // 1234567890.123456789

When the schema resolves a float, the decimal is now read from the scalar text, same as the default path. The schema still decides whether the scalar is a number, and the old double conversion stays as the fallback, so !!float 0x10 still reads as 16 and .inf still fails.

Added DecimalKeepsItsPrecisionInBothPaths to Yaml122SchemaTests; it fails before the change. dotnet test -c Release: 2517 passed.

With UseSchema, a float scalar resolved to a double before it was converted to decimal, so 1234567890.123456789 read as 1234567890.12346. Read the decimal from the scalar text, as the default path does, and keep the double conversion as a fallback.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant