Calculate Interest rate day wise in C# and VB.Net

Last Reply one month ago By dharmendr

Posted one month ago

Hello,

I am developing web application using ASP.NET C#

I want to perform mathematical operations by comparing dates

I want to develop following functionality:

Suppose user has given input as 1000 Rs. on date 1 august 2019

I have to calculate interest on 1000 and rate is 3% (Monthly)

so interest is 30 Rs.

so at 31 aug i have to show total value as 1000 + 30 (interest) = 1030 Rs.

But I have to show total value at current day also i.e. Per day interest would be : 30 (interest value)/30 (days) = 1 Rs.

So on 5 aug value should be : 1000 + 5 (interest of 5 days) = 1005

on 6 aug value should be : 1000 + 6(interest of 5 days) = 1006

and so on at last on 31 aug I have to show value = 1030 Rs

How to calculate and show this requirement as per date

Posted one month ago

Hi ashishk,

Check this example. Now please take its reference and correct your code.

C#

protected void Page_Load(object sender, EventArgs e)
{
    decimal amount = Convert.ToDecimal(1000);
    decimal intrestRate = 3;
    int noOfDays = DateTime.Now.Subtract(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).Days + 1;
    Response.Write("Intrest as on " + DateTime.Now.ToString("dd/MM/yyyy") + " is " + (amount + (((amount * intrestRate / 100) / 30) * noOfDays)).ToString());
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim amount As Decimal = Convert.ToDecimal(1000)
    Dim intrestRate As Decimal = 3
    Dim noOfDays As Integer = DateTime.Now.Subtract(New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).Days + 1
    Response.Write("Intrest as on " + Date.Now.ToString("dd/MM/yyyy") + " is " + (amount + (((amount * intrestRate / 100) / 30) * noOfDays)).ToString())
End Sub

Output

Intrest as on 08/08/2019 is 1008