c# - How to use locale independent decimal and numeric separator in format string? -


I am using the following types to format the column value (type connected to the value of decimal?): < / P>

 [DisplayFormat (DataFormatString = "{0: N2}")]   

I want to change it now in the following format:

 [DisplayFormat (DataFormatString = "{#: ##### 00. ##}")]   

However, this locale is not free because I have a lot of difficult coding and decimals I'm a divider. In fact, I want to display a string with the proper numerical and decimal separator. Also, I want the minimum two zeros after the decimal separator and after the maximum of 4 zeros. It is possible to specify such strings at compiled time

P> But, this locale is not free because I have a hard and decisive decimal separator

No, you are not; The format specifiers include . and , are respectively "decimal separator" and "thousands separators", respectively, short-term and periods should work correctly. For example, in French-French culture '#, ###. 00 ## 'should be referred to as "1 234,56":

  var culture = CultureInfo.GetCultureInfo ("fr -fr"); Decimal d = 1234.56 m; String s = d.ToString ("#, ###. 00 ## '", culture); // "1 234,56"    

Comments