yigolden / OpenSlideNET

.NET bindings for OpenSlide (http://openslide.org/)
MIT License
24 stars 6 forks source link

Floating point properties can be parsed incorrectly #42

Open jrshoare opened 2 years ago

jrshoare commented 2 years ago

When Windows regional settings do not have '.' as the decimal symbol - as is common in many European countries, for example - floating point properties such as OpenSlideImage.MicronsPerPixelX and OpenSlideImage.MicronsPerPixelY are parsed incorrectly from their string equivalent properties. This stems from the use of the double.TryParse(string, out double) method which is culture sensitive.

The OpenSlide library uses the g_ascii_dtostr method to convert doubles to strings which ensures that '.' is used as the decimal point.

The properties should parse the string using the invariant culture in double.TryParse(string, NumberStyles, IFormatProvider, out double) where IFormatProvider is CultureInfo.InvariantCulture which uses '.' as the decimal symbol.

Consider doing similar for the float and double GetProperty extension methods too.

mwijns commented 1 year ago

Thanks, had the same problem and solved it by using the method above.