Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Potential calculation erros in Double.TryParse and Double.Parse with Invariant culture and NumberStyles.Any #31

Open
AlexanderSemenyak opened this issue Sep 6, 2019 · 2 comments

Comments

@AlexanderSemenyak
Copy link

Issue (example):
Double.Parse("77,65", System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)

return 7765

Cause: System.Globalization.NumberStyles.AllowThousands
https://stackoverflow.com/questions/46109025/c-sharp-double-tryparse-with-invariantculture-returns-unexpected-result

Sample for fix:
use Public Shared NumberStyleAnyWithoutAllowThousands as NumberStyles = NumberStyles.Any - NumberStyles.AllowThousands

instead NumberStyles.Any

@AlexanderSemenyak AlexanderSemenyak changed the title Potential erros in Double.TryParse and Double.Parse with Invariant culture Potential calculation erros in Double.TryParse and Double.Parse with Invariant culture and NumberStyles.Any Sep 6, 2019
@DanWBR
Copy link
Owner

DanWBR commented Sep 6, 2019

Thanks @AlexanderSemenyak for the valuable tip. Maybe this will do the trick? ef026a9

@AlexanderSemenyak
Copy link
Author

AlexanderSemenyak commented Sep 7, 2019

Thank's :)

But also great idea - replace all Double.Parse (TryParse) for other code by this extensions methods from General.vb

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants