How can I format decimal property to currency?

前端 未结 8 1533
眼角桃花
眼角桃花 2020-12-02 21:50

I want to format a decimal value as a currency value.

How can I do this?

8条回答
  •  天涯浪人
    2020-12-02 22:43

    You can use String.Format, see the code [via How-to Geek]:

    decimal moneyvalue = 1921.39m;
    string html = String.Format("Order Total: {0:C}", moneyvalue);
    Console.WriteLine(html);
    // Output: $1,921.39
    

    See also:

    • decimal (C# Reference) at MSDN
    • Decimal parse for currency

提交回复
热议问题