Click here to Skip to main content
15,913,758 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 5:33
gtr197129-Nov-09 5:33 
GeneralRe: C# string conversion issues Pin
Richard MacCutchan29-Nov-09 5:46
mveRichard MacCutchan29-Nov-09 5:46 
AnswerRe: C# string conversion issues Pin
PIEBALDconsult29-Nov-09 5:50
mvePIEBALDconsult29-Nov-09 5:50 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 5:56
gtr197129-Nov-09 5:56 
GeneralRe: C# string conversion issues Pin
Natza Mitzi29-Nov-09 6:10
Natza Mitzi29-Nov-09 6:10 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 6:20
gtr197129-Nov-09 6:20 
GeneralRe: C# string conversion issues Pin
Richard MacCutchan29-Nov-09 6:23
mveRichard MacCutchan29-Nov-09 6:23 
GeneralRe: C# string conversion issues Pin
Natza Mitzi29-Nov-09 6:32
Natza Mitzi29-Nov-09 6:32 
Hi,
When converting from or to strings (even calling ToString(), you should ALWAYS use the culture in which you intend the formatting for. A general rule of thumb is always use English (us or uk) for internal stuff such as application logs and exporting/importing internal data, this way even when your software or data is moved between computers with different languages it will work. Use the UI culture and number formatting in the UI layer for UI interaction.

Look at this horror:
10.000
An American or english computer will read this as 10$
and a french, german and others will read this as 10000$
Fun fun fun Smile | :)

I think your code should look something like this:

String sEarnings  = txtEarnings.Text;
           double earnings;

           //Use the System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat
           //since the text box string data has the UI culture
           bool earningsParseOk = Double.TryParse(
               sEarnings, System.Globalization.NumberStyles.Any,
               System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat,
               out earnings);


           //check whether all parsing went ok
           //if not alert
           if (earningsParseOk)
           {
               //go go go
           }
           else
           {
               //error
           }



GeneralRe: C# string conversion issues Pin
PIEBALDconsult29-Nov-09 11:39
mvePIEBALDconsult29-Nov-09 11:39 
AnswerRe: C# string conversion issues Pin
Natza Mitzi29-Nov-09 6:34
Natza Mitzi29-Nov-09 6:34 
QuestionHow to creat a Hash Role programmatically Pin
Mehrdad Seyrafi29-Nov-09 0:31
Mehrdad Seyrafi29-Nov-09 0:31 
AnswerRe: How to creat a Hash Role programmatically Pin
Dave Kreskowiak29-Nov-09 5:25
mveDave Kreskowiak29-Nov-09 5:25 
AnswerRe: How to create a Hash Role programmatically Pin
Mehrdad Seyrafi29-Nov-09 19:50
Mehrdad Seyrafi29-Nov-09 19:50 
GeneralRe: How to create a Hash Role programmatically Pin
Dave Kreskowiak30-Nov-09 14:46
mveDave Kreskowiak30-Nov-09 14:46 
QuestionDatagridview sorting problem Pin
Yulianto.28-Nov-09 19:43
Yulianto.28-Nov-09 19:43 
AnswerRe: Datagridview sorting problem Pin
Yuri Vital28-Nov-09 23:42
Yuri Vital28-Nov-09 23:42 
GeneralRe: Datagridview sorting problem Pin
Yulianto.29-Nov-09 0:35
Yulianto.29-Nov-09 0:35 
QuestionReplace a letter in a Textbox? Pin
ahlm28-Nov-09 11:08
ahlm28-Nov-09 11:08 
AnswerRe: Replace a letter in a Textbox? Pin
Luc Pattyn28-Nov-09 11:12
sitebuilderLuc Pattyn28-Nov-09 11:12 
GeneralRe: Replace a letter in a Textbox? Pin
ahlm28-Nov-09 11:13
ahlm28-Nov-09 11:13 
GeneralRe: Replace a letter in a Textbox? Pin
Luc Pattyn28-Nov-09 11:28
sitebuilderLuc Pattyn28-Nov-09 11:28 
GeneralRe: Replace a letter in a Textbox? Pin
ahlm28-Nov-09 11:42
ahlm28-Nov-09 11:42 
GeneralRe: Replace a letter in a Textbox? Pin
Luc Pattyn28-Nov-09 11:54
sitebuilderLuc Pattyn28-Nov-09 11:54 
GeneralRe: Replace a letter in a Textbox? Pin
ahlm28-Nov-09 13:18
ahlm28-Nov-09 13:18 
GeneralRe: Replace a letter in a Textbox? Pin
Luc Pattyn28-Nov-09 14:07
sitebuilderLuc Pattyn28-Nov-09 14:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.