String format decimal percentage
string-format-decimal-percentage.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this line create a decimal variable.
Decimal decimalValue1 = 0.5567M;
Label1.Text = "decimal value1: " + decimalValue1.ToString();
//string format decimal to int using string.format method.
Label1.Text += "<br /><br />decimal value1 percent format: " + string.Format("{0:p}", decimalValue1);
Label1.Text += "<br />percent Format with 0 decimal digits: " + string.Format("{0:p0}", decimalValue1);
Label1.Text += "<br />percent Format with 1 decimal digits: " + string.Format("{0:p1}", decimalValue1);
Label1.Text += "<br />percent Format with 2 decimal digits: " + string.Format("{0:p2}", decimalValue1);
Label1.Text += "<br />percent Format with 3 decimal digits: " + string.Format("{0:p3}", decimalValue1);
Label1.Text += "<br /><br />using ToString method: " + decimalValue1.ToString("p1");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string format decimal percentage</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string format decimal percentage
</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 decimal percentage"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to replace a substring of a string
- How to split a string with specific delimiter to populate an array
- How to join an array elements into a new string
- How to compare two strings by ignoring case
- How to escape brackets in a formatted string
- How to count occurrences of a string within a string
- How to format a string to add commas in thousands place for a number
- 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