two decimal places for decimal/money field

前端 未结 4 2135
半阙折子戏
半阙折子戏 2020-12-31 07:02

I have a table with money field in my database. I have created entity and created decimal property for that money field. When the value of that field is displayed on My MVC3

4条回答
  •  难免孤独
    2020-12-31 07:17

    You have to format the string.

    One thing you can do if it money you want to display is:

    static void Main () 
    {
        decimal x = 0.999m;
        decimal y = 9999999999999999999999999999m;
        Console.WriteLine("My amount = {0:C}", x);
        Console.WriteLine("Your amount = {0:C}", y);
    }
    

    }

    OUTPUT: Output

    My amount = $1.00
    Your amount = $9,999,999,999,999,999,999,999,999,999.00

    the {0:C} is the currency Format

    Hope this helps!

提交回复
热议问题