开发者

mvc3 web grid number/decimal formatting?

How can I format the following and specify the number of decimal places in an mvc3/asp.net/webgrid?

grid.Column("Val", format: @&开发者_StackOverflowlt;text>@((decimal)100/3) </text>)

Thx!


You can format decimal values in C# as so:

String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 123.4);         // "123.40"
String.Format("{0:0.00}", 123.0);         // "123.00"

Given the above, you should be able to do:

grid.Column("Val", format: @<text>@String.Format("{0:0.00}", (decimal)(100/3)) </text>)

More information on formatting decimal, doubles and floats: http://www.csharp-examples.net/string-format-double/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜