String format currency
string-format-currency.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this line create an int variable.
int number = 123;
//this line create a decimal variable.
decimal decimalValue = 225.85M;
//this line create a double variable.
double doubleValue = 599.99;
Label1.Text = "number: " + number;
Label1.Text += "<br />formatted string..............<br />";
//format string using ToString method.
Label1.Text += "<br />string format integer to currency: " + number.ToString("c");
Label1.Text += "<br />string format integer to currency other option: " + number.ToString("c1");
Label1.Text += "<br /><br />string format decimal to currency: " + decimalValue.ToString("c");
Label1.Text += "<br />string format decimal to currency another option: " + decimalValue.ToString("c1");
Label1.Text += "<br /><br />string format double to currency: " + doubleValue.ToString("c");
//format string using string.format method.
Label1.Text += "<br /><br />string format number to currency: " + string.Format("{0:c}", number);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string format currency</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string format currency
</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"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to format a string as a number with sign
- How to format a string as a fixed length number
- String format number two digits
- How to format a string with padding
- How to replace a character in a string
- How to perform string replace by ignoring case
- How to replace first occurrence of a substring within a string
- String contains regex
- How to check whether a string contains numbers only
- String contains list of strings