Sign in to follow this  
jbguil09

[SlimDX] CultureInfo for float.TryParse in SmdLoader

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by kanato
Would 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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this