可能重複:
Using String Format to show decimal upto 2 places or simple integer
How to set decimal point in 2 decimal places?如何在mvc3,C#中將數字顯示爲2位小數?
我有我的看法價格區域。它具有以下值2.5 and 44.
我想顯示此值2.50 and 44.00
我使用下面的代碼
@{decimal prolistprice = decimal.Parse(item.OtherFields["Price"].ToString());}
[email protected](prolistprice, 2, MidpointRounding.AwayFromZero)
其中item.OtherFields["price"] is a object
我將其轉換爲字符串,然後十進制
但Math.round沒有工作,那麼顯示2.5,只有44 .. 誰能幫助這個
爲什麼標題說 「整」? –
你可以按照這個帖子: http://stackoverflow.com/questions/6951335/using-string-format-to-show-decimal-upto-2-places-or-simple-integer –
HTTP:/ /stackoverflow.com/questions/5428289/mvc3-decimal-truncated-to-2-decimal-places-on-edit – alexsuslin