You must Sign In to post a response.
  • Category: ASP.NET

    How To Calculate Percentage of a TextBox Value in Asp.Net C#

    Hi Developers,

    I want to Calculate a TextBox value by Percentage(int,float value).

    If My


    TextBox Value=1000

    Result 1000 + 5.5%

    Result should be =1055.00
    i have tried and google it.
    I cant able To get exact answer

    So please help me friends for i am done this task.

    Thanks with

  • #767027

    try this Query in sql

    declare @tot1 decimal(18,2)
    set @tot1 = (5.5/100*1000)
    select 1000+@tot1

    Answer is this :1055.00

    in C# Code

    double tot1;
    double tot2;
    tot1=(5.5/100) * 1000;
    tot2 = 1000 + @tot1;

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767028
    Can you try the following logic. Its simple % calculation only. try to put correct "(" in the expression.

    double TxtValue = 0.0;
    double.Tryparse(TextBox1.Text, out TxtValue );
    double ResultValueL = TxtValue + (TxtValue * 5.5/100)

    By Nathan
    Direction is important than speed

  • #767029

    In webform.aspx page write below code

    Take two textboxe's TextBox1 and TextBox2, one Label and one button(btn)

    in webform.aspx.cs page

    protected void Page_Load(object sender, EventArgs e)
    Label1.Visible = false;

    protected void btn_Click(object sender, EventArgs e)
    decimal a =decimal.Parse(TextBox1.Text);
    decimal b = decimal.Parse(TextBox2.Text);
    decimal c = a * b/100;
    decimal d = a + c;
    string s= String.Format("{0:0.00}", d);
    Label1.Text = s.ToString();
    Label1.Visible = true;

    output will be 1055.00

    Sridhar Thota.
    Editor: DNS Forum.

  • #767038
    Try this:

    var a = 1000;// Input
    var b = (1000 * 5.5) / 100;
    var c = a + b;

  • #767059

    Try below sample code

    int a= Convert.ToInt32(txt1.Text);// i.e. 1000
    int b= Convert.ToInt32((Convert.ToFloat(txt2.Text)/100))*a;
    int c=a+b;

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #767064
    it is rally simple, either you can use javascript or code behind to calculate percentage

    //code behind
    float percentage;
    percentage = ((float)(gradeA/students))*100.0);
    percentLabel.Text = String.Format("{0.00}", percentage);
    //using javascript
    < script language="javascript">
    function calculatePercentage()
    var szPercentage = "5.5";
    var result = (szPercentage / 100) * 1000
    result = result + 1000;
    < /script>

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

Sign In to post your comments