Simple Interest Calculator in ASP.NET C#
Simple Interest Rate Calculator in asp.net using C#
Get User input Principal Amount, Period(in Years/Month),Interest Rate. Total Amount =(Interest Amount for the Duration+Principal).
Add Text fields and dropdownlist
<form id="form1" runat="server">
<h1> Simple Interest Calculator in ASP.NET</h1>
<div>
<b>Principal Amount:</b>
<asp:TextBox ID="txtPrincipalAmt" runat="server"></asp:TextBox><br />
<b>Period:</b>
<asp:TextBox ID="txtPeriod" runat="server"></asp:TextBox><asp:DropDownList ID="DropDownListPeriods"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListPeriods_SelectedIndexChanged">
<asp:ListItem>Years</asp:ListItem>
<asp:ListItem>Months</asp:ListItem>
</asp:DropDownList><br />
<b>Interest Rate(%):</b>
<asp:TextBox ID="txtInterest" runat="server"></asp:TextBox> % per year.<br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" CssClass="btnStyle"/>
</div>
<div>
<h3>output of simple interest calculation</h3>
<b>Total Amount:</b><asp:TextBox ID="txtTotalAmt" runat="server"></asp:TextBox> USD<br />
<b>Interest Amount:</b><asp:TextBox ID="txtIntAmt" runat="server"></asp:TextBox> USD<br />
</div>
</form>
<h1> Simple Interest Calculator in ASP.NET</h1>
<div>
<b>Principal Amount:</b>
<asp:TextBox ID="txtPrincipalAmt" runat="server"></asp:TextBox><br />
<b>Period:</b>
<asp:TextBox ID="txtPeriod" runat="server"></asp:TextBox><asp:DropDownList ID="DropDownListPeriods"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListPeriods_SelectedIndexChanged">
<asp:ListItem>Years</asp:ListItem>
<asp:ListItem>Months</asp:ListItem>
</asp:DropDownList><br />
<b>Interest Rate(%):</b>
<asp:TextBox ID="txtInterest" runat="server"></asp:TextBox> % per year.<br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" CssClass="btnStyle"/>
</div>
<div>
<h3>output of simple interest calculation</h3>
<b>Total Amount:</b><asp:TextBox ID="txtTotalAmt" runat="server"></asp:TextBox> USD<br />
<b>Interest Amount:</b><asp:TextBox ID="txtIntAmt" runat="server"></asp:TextBox> USD<br />
</div>
</form>
On DropDownList selection Change
protected void DropDownListPeriods_SelectedIndexChanged(object sender, EventArgs e)
{
String period = DropDownListPeriods.SelectedValue;
if (period.ToLower() == "years")
{
Decimal result;
if (Decimal.TryParse(txtPeriod.Text, out result))
{
txtPeriod.Text = (result / 12).ToString();
}
}
else
{
Decimal result;
if(Decimal.TryParse(txtPeriod.Text, out result))
{
txtPeriod.Text = (result * 12).ToString() ;
}
}
}
{
String period = DropDownListPeriods.SelectedValue;
if (period.ToLower() == "years")
{
Decimal result;
if (Decimal.TryParse(txtPeriod.Text, out result))
{
txtPeriod.Text = (result / 12).ToString();
}
}
else
{
Decimal result;
if(Decimal.TryParse(txtPeriod.Text, out result))
{
txtPeriod.Text = (result * 12).ToString() ;
}
}
}
//Calculate Interest rate Button Click Event Handler
protected void btnCalculate_Click(object sender, EventArgs e)
{
Decimal pricipalAmt;
Decimal.TryParse(txtPrincipalAmt.Text, out pricipalAmt);
Decimal intRate;
Decimal.TryParse(txtInterest.Text, out intRate);
String period = DropDownListPeriods.SelectedValue;
Decimal Duration;
Decimal.TryParse(txtPeriod.Text, out Duration);
if (period.ToLower() == "months")
{
Duration = Duration / 12;
}
//txtTotalAmt
Decimal totalIntAmount = ((pricipalAmt * intRate * Duration) / 100);
txtIntAmt.Text = totalIntAmount.ToString();
txtTotalAmt.Text = (totalIntAmount + pricipalAmt).ToString();
}
{
Decimal pricipalAmt;
Decimal.TryParse(txtPrincipalAmt.Text, out pricipalAmt);
Decimal intRate;
Decimal.TryParse(txtInterest.Text, out intRate);
String period = DropDownListPeriods.SelectedValue;
Decimal Duration;
Decimal.TryParse(txtPeriod.Text, out Duration);
if (period.ToLower() == "months")
{
Duration = Duration / 12;
}
//txtTotalAmt
Decimal totalIntAmount = ((pricipalAmt * intRate * Duration) / 100);
txtIntAmt.Text = totalIntAmount.ToString();
txtTotalAmt.Text = (totalIntAmount + pricipalAmt).ToString();
}
OUTPUT
For 1 year interest rate of 6% amount is $1 ==> after 1yr Total Amount is 1.06 $ interest earned is 0.06.
Tags:Simple Interest Calculator in ASP.NET C#,Simple Interest Calculator in C#,Simple Interest calculator in WPF,Button click Event Handler, DropDownList AutoPostback,DropDownList SelectionIndexChanged Event handler, Decimal.TryParse.
No comments:
Post a Comment