ASP.Net/Language Basics/Double
Версия от 15:30, 26 мая 2010; (обсуждение)
Read TextBox input, convert to double and do calculation (C#)
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
void Page_Load()
{
if (Page.IsPostBack)
{
lblTax.Text = "Your tax bill would be $";
lblTax.Text += Convert.ToString(Convert.ToInt32(txtEarnings.Text)*Convert.ToInt32(txtTaxRate.Text)/100);
lblTax.Visible=true;
}
}
</script>
<html>
<head>
<title>Calculate Tax Bill</title>
</head>
<body>
<h3>Tax rates
</h3>
<form runat="server">
Please enter your earnings: $
<asp:TextBox id="txtEarnings" runat="server" width="80px"></asp:TextBox>
<br />
Please enter your tax rate, for example enter "7" for 7%
<asp:TextBox id="txtTaxRate" runat="server" width="30px"></asp:TextBox>
<br />
<asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
<br />
<asp:Label id="lblTax" runat="server" visible="False"></asp:Label>
<br />
</form>
</body>
</html>
Use Double to calculate Tax (C#)
<script Language="c#" runat="server">
void Page_Load()
{
double dblEarn = 150;
double dblTax = 23;
double dblTotal = dblEarn - ((dblEarn/100)*dblTax);
Display1.Text = dblTotal.ToString();
}
</script>
<html>
<head>
<title>Declaring Variables</title>
</head>
<body>
<asp:label id="Display1" runat="server" />
</body>
</html>