Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not serializing floats properly #60

Open
snarlynarwhal opened this issue Mar 27, 2023 · 2 comments
Open

Not serializing floats properly #60

snarlynarwhal opened this issue Mar 27, 2023 · 2 comments
Labels
bug Something isn't working PR welcome User contribution/PR is welcome

Comments

@snarlynarwhal
Copy link

It seems like floats < 1.0 get serialized weird. For example, .1 gets serialized as 0.100000001 and .99 gets serialized as 0.99000001.

@xoofx xoofx added bug Something isn't working PR welcome User contribution/PR is welcome labels Aug 4, 2023
@lilith
Copy link
Contributor

lilith commented Jan 31, 2024

I wouldn't call this a Tomlyn bug - it's getting 0.100000001 from your code since that's what a 32-bit floating point is stored as in memory (well base 2, but the equivalent is that). You could switch to double or decimal depending on your use case to reduce imprecision, but I don't think Tomlyn should change the value it's getting based on assumptions about the input being base 10 and the user's aesthetic preferences. A custom converter is probably where any such logic could stay, in my opinion.

@lilith
Copy link
Contributor

lilith commented Feb 1, 2024

I apologize, it looks like it may be possible to improve the situation, although I'm uncertain if we can do so with the built-in formatters in .NET. 026f953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome User contribution/PR is welcome
Projects
None yet
Development

No branches or pull requests

3 participants