开发者

mvc3 web grid number/decimal formatting?

开发者 https://www.devze.com 2023-04-05 19:49 出处:网络
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>)

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

精彩评论

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