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

前端 未结 11 1138
予麋鹿
予麋鹿 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条回答
  •  眼角桃花
    2020-11-29 04:40

    Try with

    ToString("#,##0.00")
    

    From MSDN

    *The "0" custom format specifier serves as a zero-placeholder symbol. If the value that is being formatted has a digit in the position where the zero appears in the format string, that digit is copied to the result string; otherwise, a zero appears in the result string. The position of the leftmost zero before the decimal point and the rightmost zero after the decimal point determines the range of digits that are always present in the result string.

    The "00" specifier causes the value to be rounded to the nearest digit preceding the decimal, where rounding away from zero is always used. For example, formatting 34.5 with "00" would result in the value 35.*

提交回复
热议问题