Lee3305

A friend of mine from the UK was testing a program I wrote in which there are parts where the user needs to input a double, almost always a decimal. Since he is from the UK, he has his regional setting on Windows set to European, thus, our decimal points are commas for them. Since my program is looking for decimal points, it crashes when it sees a comma used in that manner. Of course, when he set his regional settings to US, the program ran fine with no errors, but then he cant use any of his other programs. So, I need a way to make my program compatible with input in which a comma is a decimal point. Any help would be greatly appreciated.

Thanks in advance,

Lee



Re: Visual C++ Language Question about accepting strings of European format

einaros

How are you reading the decimals If you're using STL streams, you can set the locale to the OS default such as:

Code Snippet

locale loc("");

cin.imbue(loc);

cout.imbue(loc);






Re: Visual C++ Language Question about accepting strings of European format

Lee3305

Im reading them through a text box.



Re: Visual C++ Language Question about accepting strings of European format

einaros

You will have to be more specific. Are you using the MFC Native or managed code ATL




Re: Visual C++ Language Question about accepting strings of European format

Lee3305

Sorry, Its manged C++ using Windows Forms



Re: Visual C++ Language Question about accepting strings of European format

einaros

Are you manually looking for a decimal point, or are you using System::Convert or similar




Re: Visual C++ Language Question about accepting strings of European format

Lee3305

On the TextBox_TextChanged event, I assign the TextBox->Text to a property to pass back on the main form. Yes, I also use System::Convert.



Re: Visual C++ Language Question about accepting strings of European format

einaros

One of the System::Convert overrides takes a string as first parameter, and an IFormatProvider as the second. Pass a NumberFormatInfo instance initialized to the culture of your choice, or use NumberFormatInfo::CurrentInfo for the format currently configured by the user's operating system.




Re: Visual C++ Language Question about accepting strings of European format

Lee3305

Thanks, Ill definately give this a try when I get off work