String format decimal to int
string-format-decimal-to-int.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this section create decimal variables.
Decimal decimalValue1 = 123.55M;
Decimal decimalValue2 = 555.45M;
Label1.Text = "decimal value1: " + decimalValue1.ToString();
Label1.Text += "<br />decimal value2: " + decimalValue2.ToString();
//string format decimal to int using string.format method.
Label1.Text += "<br /><br />decimal value1 to int: " + string.Format("{0:0}", decimalValue2);
Label1.Text += "<br />decimal value2 to int: " + string.Format("{0:0}", decimalValue2);
Label1.Text += "<br /><br />decimal value1 (Math.Floor): " + string.Format("{0:0}", Math.Floor(decimalValue1));
Label1.Text += "<br />decimal value1 (Math.Round): " + string.Format("{0:0}", Math.Round(decimalValue1));
Label1.Text += "<br /><br />decimal value2 (Math.Floor): " + string.Format("{0:0}", Math.Floor(decimalValue2));
Label1.Text += "<br />decimal value2 (Math.Round): " + string.Format("{0:0}", Math.Round(decimalValue2));
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string format decimal to int</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string format decimal to int
</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 to int"
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 as currency without decimal
- How to format a string as currency with dollar sign
- How to format a string as negative currency
- How to format a string as a date
- How to format a string as a date without time
- How to format a string as decimal
- How to format a decimal string to currency