OpenWeatherMap-API-CSharp icon indicating copy to clipboard operation
OpenWeatherMap-API-CSharp copied to clipboard

Decimal Seeparator

Open wvdvegt opened this issue 1 year ago • 2 comments

Somehow this code seems to use the users decimal separator (in my case a comma) and thus ignoreing the . (US & as far as i know part of the JSON's standard).

Result is wind speeds are 1000 fold of what they are in the data retrieved

"speed": 11.32 thus results in the demo printing 1132 m/s/

wvdvegt avatar Jan 05 '24 11:01 wvdvegt

Debugging a bit shows windata at line 45 of Wind.cs correctly shows dots as decimal separator, but windData.SelectToken("speed") shows {11,32} as value in the Watch window.

wvdvegt avatar Jan 05 '24 12:01 wvdvegt

Solution (note; only tested in a country with a , as separator):

replace:

SpeedMetersPerSecond = double.Parse(windData.SelectToken("speed").ToString(), CultureInfo.InvariantCulture);

by

SpeedMetersPerSecond = windData.SelectToken("speed").Value<Double>();

thus preventing converting bwteeen double and string.

This change should be applied at all simimar code. And best to remove it for other data types as integers as well.

wvdvegt avatar Jan 05 '24 12:01 wvdvegt