Currency formatting

Jul 3, 2013 at 7:19 PM
Hi, how can I give currency format to a column?

I am adding columns like this:

columns.Add(i => i.ADecimalField).Titled("whatever");

is there a way to give it a currency format?
Coordinator
Jul 4, 2013 at 3:57 AM
Hi, yes.

You can use Format method to setup format specifier:
columns.Add(i => i.ADecimalField).Titled("whatever").Format("{0:F}");
More about specifiers: http://msdn.microsoft.com/en-us/library/fzeeb5cd.aspx

Also you can use RenderValueAs to specify custom layout for rendering cell value
Jul 4, 2013 at 5:01 PM
Excellent.

Thank you
Jun 2, 2014 at 4:17 PM
I was not able to get the above solution working. My model returns a double. Here is the code below.

columns.Add(i => i.Cost) //where cost is a double (1.99) etc.
    .Sortable(true)
    .Sanitized(false)
    .Encoded(false)
    .Format("{0:F}")  // Does not work for some reason
    .RenderValueAs(i => "$" + i.Cost  ); //had to manually format
Coordinator
Jun 2, 2014 at 5:27 PM
Try to use:
 .Format("{0:C}")
See more about format specifiers: http://msdn.microsoft.com/en-en/library/d8ztz0sa(v=vs.110).aspx