ASP.Net/Language Basics/Double

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Read TextBox input, convert to double and do calculation (C#)

   <source lang="csharp">

<%@ 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>

Tax rates

   <form runat="server">
       Please enter your earnings: $ 
       <asp:TextBox id="txtEarnings" runat="server" width="80px"></asp:TextBox>
       
Please enter your tax rate, for example enter "7" for 7% <asp:TextBox id="txtTaxRate" runat="server" width="30px"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
<asp:Label id="lblTax" runat="server" visible="False"></asp:Label>
</form>

</body> </html>

      </source>
   
  


Use Double to calculate Tax (C#)

   <source lang="csharp">

<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>

      </source>