My CultureInfo.InvariantCulture is not being invariant

334 Views Asked by At

I've got a very strange problem. My C# interactive gives me:

> string.Format("{0:P1}", 0, CultureInfo.InvariantCulture)
"0.0%"

However, in the debugger, the same expression yields something else:

> string.Format("{0:P1}", 0, CultureInfo.InvariantCulture)
"0.0 %"

Does anybody have any ideas how this can happen?

1

There are 1 best solutions below

4
chtenb On

Ok, it seems I messed up the order of arguments. I should have

string.Format(CultureInfo.InvariantCulture, "{0:P1}", 0)

Apparently the compiler and runtime are fine with superfluous format arguments and will happily discard them for you.

The expressions in the OP will have used the Current Culture which may indeed have different semantics between framework and core as @JeroenMostert suggested.