Reputation: 13367
How can I format the following and specify the number of decimal places in an mvc3/asp.net/webgrid?
grid.Column("Val", format: @<text>@((decimal)100/3) </text>)
Thx!
Upvotes: 1
Views: 9320
Reputation: 12440
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/
Upvotes: 5