US dollar decimal format

<%= Math.Round(netValue)%>

One example of this conclusion might be -1243313

How can I make sure it is formatted as US currency (with "$", valid commas, etc.)?

+5
source share
4 answers

May be:

<%=string.Format(CultureInfo.GetCultureInfo(1033), "{0:C}", Math.Round(netValue)) %>

(1033 - locale identifier for the culture "en-us")

+10
source

If the thread culture already has an en-US value, you do not need to specify it.

<%= Math.Round(netValue).ToString("C") %> 

Otherwise, to get a culture for the United States, first create a culture object.

CultureInfo usaCulture = new CultureInfo("en-US");

You can then pass this to the ToString method for the decimal object.

<%= Math.Round(netValue).ToString("C", usaCulture) %> 
+3
source

format C :

decimal moneyvalue = 1921.39;
string output = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(output);

: , .

+1
source