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/
精彩评论