Can I set the decimal symbol to use everywhere in my application

前端 未结 2 920
执笔经年
执笔经年 2021-01-22 17:04

I tracked down a bug in my application that occurred for people in countries where the default decimal symbol was a comma instead of a period. Is there any way in C# to set the

2条回答
  •  不思量自难忘°
    2021-01-22 17:29

    I you still need to do that you can change the CurrentCulture on the thread like so:

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-Us");
    

    Chooe a Culture that has the decimal properties you need.

    var numpre = 1.1.ToString();
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-Us");
    var numpost = 1.1.ToString();
    numpre.Dump();
    numpost.Dump();
    

    Output:

    1,1
    1.1

提交回复
热议问题