I run this part of code on my PC. The system Operating is Windows 10 Enterprise.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
static void Main(string[] args)
{
string text_double = "0.7598";
string message = "Using double.Parse(): ";
try
{
double confidence = double.Parse(text_double);
message += text_double + " Converted To " + confidence;
}
catch (Exception ex)
{
message += ex.Message;
}
Console.WriteLine(message);
message = "Using Convert.ToDouble: ";
try
{
double confidence = Convert.ToDouble(text_double);
message += text_double + " Converted To " + confidence;
}
catch (Exception ex)
{
message += ex.Message;
}
Console.WriteLine(message);
Console.ReadKey();
return;
}
Running The executable file on my PC returns expected results:
Using double.Parse(): 0.7598 Converted To 0.7598
Using Convert.ToDouble: 0.7598 Converted To 0.7598
But when I run the executable file on my other computer running Win Server 2012 DataCenter, it always returns error as follows:
Using double.Parse(): input string was not in a correct format
Using Convert.ToDouble: input string was not in a correct format
What is wrong with my Windows server ?
[Added]:
I realized from the comments that my Windows server has a different culture ,but I don't want to change my code when it is needed to be run on another PC. There may be other PCs with different cultures as well.
Is there any independent culture?