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

前端 未结 11 1097
予麋鹿
予麋鹿 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:20
    CultureInfo us = new CultureInfo("en-US");
    TotalAmount.ToString("N", us)
    
    0 讨论(0)
  • 2020-11-29 04:27
    int number = 1234567890;
    Convert.ToDecimal(number).ToString("#,##0.00");
    

    You will get the result 1,234,567,890.00.

    0 讨论(0)
  • 2020-11-29 04:28

    For Razor View:

    $@string.Format("{0:#,0.00}",item.TotalAmount)
    
    0 讨论(0)
  • 2020-11-29 04:29
    string Mynewcurrency = DisplayIndianCurrency("7743450.00");
            private string DisplayIndianCurrency(string EXruppesformate) 
            { 
            string fare = EXruppesformate;
            decimal parsed = decimal.Parse(fare, CultureInfo.InvariantCulture);
            CultureInfo hindi = new CultureInfo("en-IN");
         // string text = string.Format(hindi, "{0:c}", parsed);if you want <b>Rs 77,43,450.00</b>
        string text = string.Format(hindi, "{0:N}", parsed); //if you want <b>77,43,450.00</b>
          return ruppesformate = text;
        }
    
    0 讨论(0)
  • 2020-11-29 04:30

    Your question is not very clear but this should achieve what you are trying to do:

    decimal numericValue = 3494309432324.00m;
    string formatted = numericValue.ToString("#,##0.00");
    

    Then formatted will contain: 3,494,309,432,324.00

    0 讨论(0)
  • 2020-11-29 04:30

    All that is needed is "#,0.00", c# does the rest.

    Num.ToString("#,0.00"")

    • The "#,0" formats the thousand separators
    • "0.00" forces two decimal points
    0 讨论(0)
提交回复
热议问题