Re: Float conversion problem
Your question is excellently answered by MSDN. Look up System.Convert class and read about System.Convert.ToDouble(string, IFormatProvider). In short it says that you can pass an instance of NumberFormatInfo as IFormatProvider. NumberFormatInfo has members such as NumberDecimalSeparator.
HTH!
Re: Float conversion problem
Oh, and by the way, I don't think different languages of XP is the issue, rather it is differences in Regional Settings. When you are converting user input you should use the overload of ToDouble in your post, not the one I suggested, because as I understand it your overload uses formatting info from Regional Settings. This way the user has the option to choose any format he/she likes of floating numbers and you will be able to convert them successfully.
Cheers.
Re: Float conversion problem
Actually, its a bit wierd for me. The convert should basically fail because there's a comma (,) in the string !! Anyways, what Anders says is correct.
Quote:
Originally Posted by Anders
I don't think different languages of XP is the issue, rather it is differences in Regional Settings.
The regional setting are there in the windows registry. It picks up the basic formats from there - for dates, currencies etc. Try using the overloads specifying the formats. By the way, it makes sense, since you are using a German Version of the OS..the inputs you would be providing would be as per your regional settings. So, in a way that is correct and part of "Localization" of your application according to the .Net framework. However, if you want a specific way, go as suggested by Anders. :thumb:
Re: Float conversion problem
Thank you. Now I am using
Code:
System.Globalization.NumberFormatInfo nfi =
new System.Globalization.CultureInfo( "en-US", false ).NumberFormat;
fl = (float)System.Convert.ToDouble( st, nfi );
which converts to the same float without caring about region settings.
gbr
Re: Float conversion problem
Quote:
Originally Posted by exterminator
The convert should basically fail because there's a comma (,) in the string !!
Not neccessarily, as I understand it. My current Regional Settings has a comma as the grouping character and thus it is a legal characters that is just discarded when converting. I think. Not sure :-)