C# float.Parse Ignoring Culture

Viewed 366

Some test code:

string Input = "13.00"
float Output = float.Parse(Input, new CultureInfo("en-US"));

On my PC (Win10 x64, English - US) the value of output is 13.

On another PC (Win10 x64) that I don't have access to where the language is US English but the region is Denmark, the value of Output is 1300.

I've tried to recreate the settings on my PC by swapping comma and decimal point and setting the system locale to Denmark but it always gives a value of 13 for me.

I've tried it on some German Win10 x64 PCs and they also set Output to 13.

I thought the purpose of specifying the culture was to force the use of the comma and decimal point to a specific usage?

Any ideas what I am doing wrong here? Thanks!

Update

Adding the following code:

string Debug = string.Format("{0:0.00}", Output);

results in Debug containing "13.00" on our test PCs (English and German) and "1300,00" on the problem PC.

Update 2

Changing from new CultureInfo("en-US") to CultureInfo.InvariantCulture seems to get the correct output of 13 on the problem PC.

What is the difference between en-US and invariant and why would that only manifest itself on this one example PC that we have seen so far?

0 Answers
Related