Nothing
Nothing

Reputation: 2642

Format money to currency in asp.net mvc c#

I have one field in database, store price of my products. Its datatype is money and I want to format it like : 8.20, 10.00, and 100,00.00 This is my code :

$<%: string.Format("{0:00.00}", price)%>

But the output is not like what I want, anyone have any idea about that? Thanks.

Upvotes: 1

Views: 4345

Answers (3)

codingbadger
codingbadger

Reputation: 44032

Try this:

<%: string.Format("{0:N2}", price) %>

Upvotes: 0

GvS
GvS

Reputation: 52538

I think you are looking for:

  $<%: string.Format("{0:#0.00}", price)%> 

This will skip the leading 0 for numbers under 10.

See the MSDN page for more information.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

Try using the currency format (0:C):

<%: string.Format("{0:C}", price) %>

Upvotes: 6

Related Questions