dwsim5 icon indicating copy to clipboard operation
dwsim5 copied to clipboard

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

Open AlexanderSemenyak opened this issue 6 years ago • 2 comments

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 avatar Sep 06 '19 02:09 AlexanderSemenyak

Thanks @AlexanderSemenyak for the valuable tip. Maybe this will do the trick? https://github.com/DanWBR/dwsim5/commit/ef026a927d1b89dd5c9243f28ba82a66dff60f07

DanWBR avatar Sep 06 '19 12:09 DanWBR

Thank's :)

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

AlexanderSemenyak avatar Sep 07 '19 04:09 AlexanderSemenyak