[SlimDX] CultureInfo for float.TryParse in SmdLoader

This topic is 3070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

The CultureInfo is not set in the SampleFramework, so the TryParse in SmdLoader return false if your default CultureInfo as not "0.00000" format for float. (Mine is "0,0000"). I just add Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); in the run function of the SampleFramework

Share on other sites
Hmm, yes, since the SMD sample file uses a decimal seperator of ".", I suppose we should probably set the culture or at least use the other try/format.

If you are using the latest (or the SDK) then simply change line 108 of SmdLoader.cs from
if (!float.TryParse(value, out result)) {

to
if (!float.TryParse(value, Numberstyles.Float, CultureInfo.GetCultureInfo("en-us").NumberFormat, out result)) {

Share on other sites
Would it be preferred to use CultureInfo.InvariantCulture instead of CultureInfo.GetCultureInfo("en-us")?

Share on other sites
Quote:
 Original post by kanatoWould it be preferred to use CultureInfo.InvariantCulture instead of CultureInfo.GetCultureInfo("en-us")?

Yes, that should work as well, as I believe the InvariantCulture is assumed to be an "English" culture and hence will use "." as the decimal separator and "," as the group separator.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 22
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×