Custom Currency symbol and decimal places using decimal.ToString(“C”) and CultureInfo

后端 未结 5 1934
长发绾君心
长发绾君心 2021-01-05 05:00

I have a problem with decimal.ToString(\"C\") override. Basically what I wants to do is as follows:

CultureInfo usCulture = new CultureInfo(\"en         


        
5条回答
  •  再見小時候
    2021-01-05 05:54

    To get a format like RM 11,123,456.00 you also need to set the following properties

    CurrentCulture modified = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
    Thread.CurrentThread.CurrentCulture = modified;
    var numberFormat = modified.NumberFormat;
    numberFormat.CurrencySymbol = "RM";
    numberFormat.CurrencyDecimalDigits = 2;
    numberFormat.CurrencyDecimalSeparator = ".";
    numberFormat.CurrencyGroupSeparator = ",";
    

    If you do that at application startup then that should make ms-MY format like en-US but with the RM currency symbol every time you call the ToString("C") method.

提交回复
热议问题