Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq sum how to display as currency

Tags:

c#

linq

razor

I have the following in a razor view:

<td>@payments.Sum(p => p.Amount)</td>

I want it to display as a currency so have '$' and two decimals on the end.

I think normally you go something like {0:C}.

I don't know how to incorporate this into what I've got as the Sum does not have an overload for format.

Do I need to do this with a css class?

like image 546
user2005657 Avatar asked Jan 27 '26 13:01

user2005657


1 Answers

You would do this:

<td>@String.Format("{0:C}", payments.Sum(p => p.Amount))</td>
like image 154
Yuck Avatar answered Jan 29 '26 01:01

Yuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!