String format number two digits
string-format-number-two-digits.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 = 125.9M;
//this line create a double variable.
double doubleValue = 100.123;
Label1.Text = "number: " + number;
Label1.Text += "<br />formatted string..............<br />";
//format string using ToString method.
Label1.Text += "<br />format integer number two digits: " + number.ToString("0.00");
Label1.Text += "<br />format decimal value two digits: " + decimalValue.ToString("0.00");
Label1.Text += "<br />format double value two digits: " + doubleValue.ToString("0.00");
//format string using string.format method.
Label1.Text += "<br />format string 2 digits number: " + string.Format("{0:0.00}", number);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string format number two digits</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string format number two digits
</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 number two digits"
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
- How to format a string as currency
- 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 format a string as hexadecimal
- How to convert an integer to fixed length hex string format
- How to format a string with padding