format a number with commas and decimals in C# (asp.net MVC3)

前端 未结 11 1143
予麋鹿
予麋鹿 2020-11-29 03:40

I Need to display a number with commas and decimal point.

Eg: Case 1 : Decimal number is 432324 (This does not have commas or decimal Points) Need to display it

11条回答
  •  Happy的楠姐
    2020-11-29 04:38

    Maybe you simply want the standard format string "N", as in

    number.ToString("N")
    

    It will use thousand separators, and a fixed number of fractional decimals. The symbol for thousands separators and the symbol for the decimal point depend on the format provider (typically CultureInfo) you use, as does the number of decimals (which will normally by 2, as you require).

    If the format provider specifies a different number of decimals, and if you don't want to change the format provider, you can give the number of decimals after the N, as in .ToString("N2").

    Edit: The sizes of the groups between the commas are governed by the

    CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes
    

    array, given that you don't specify a special format provider.

提交回复
热议问题