Format number as money

前端 未结 4 1480
忘掉有多难
忘掉有多难 2020-12-11 14:46

How do I format a number to look like this: 9,000 my database field is in money data type, when I pull it up I see it like this: 9000.0000 that don\'t look right to me (I w

相关标签:
4条回答
  • 2020-12-11 15:24
    decimal money = 1000;
    Response.Write(string.Format("{0:C}", money));
    

    The above is an example in C#.

    0 讨论(0)
  • 2020-12-11 15:29

    You need to do a "formatting" function (in whatever language you're using) that will return the data in a currency format. Another answer already describes the code in C#. Here's vbscript:

    Dim Amount
    Amount = 2000
    Response.Write(FormatCurrency(Amount))
    

    How your database viewing application reads the data and how it is actually stored in the database may be two different things.

    0 讨论(0)
  • 2020-12-11 15:30

    Thought I'd add a C# 6 option with interpolated strings:

    decimal money = 9000m;
    string formatted = $"{money:C}";
    
    0 讨论(0)
  • 2020-12-11 15:31

    While you could call string.format, I think it's easier to just call ToString on it.

    decimal money = 9000m;
    string formattedMoney = money.ToString("C");
    
    0 讨论(0)
提交回复
热议问题