String format currency with dollar sign
string-format-currency-with-dollar-sign.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Globalization" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this line create an int variable.
int number = 124;
CultureInfo usCulture = new CultureInfo("en-US");
//this line create a decimal variable.
decimal decimalValue = 431.86M;
//this line create a double variable.
double doubleValue = 666.15;
Label1.Text = "Integer: " + number;
Label1.Text += "<br />Decimal: " + decimalValue;
Label1.Text += "<br />Double: " + doubleValue;
Label1.Text += "<br /><br />string format currency with dollar sign..............";
//format string using ToString method.
Label1.Text += "<br />integer: " + number.ToString("c");
Label1.Text += "<br />integer: " + number.ToString("c0");
Label1.Text += "<br />decimal value: " + decimalValue.ToString("c");
Label1.Text += "<br />double value: " + doubleValue.ToString("c");
//format string using string.format method.
Label1.Text += "<br /><br />format integer using string.format method: " + string.Format("{0:c0}", number);
Label1.Text += "<br />format integer with [en-US] culture: " + string.Format(usCulture, "{0:c0}", number);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string format currency with dollar sign</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string format currency with dollar sign
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string format currency with dollar sign"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to format a string as currency without decimal
- How to format a string as currency without dollar sign
- How to format a string as currency using localization
- How to format a date string as yyyy-MM-dd format
- How to format a string as a date with milliseconds
- How to format a decimal string to currency
- How to format a decimal string to int
- How to remove special characters from a string
- How to remove non numeric characters from a string
- How to reverse a string