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

Float:

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

Thanks with

Paul.S
• Hi
paul

try this Query in sql

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

in C# Code

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

Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com

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

• 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

• Hi

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.

• Hi,
Try this:

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

• Hi,

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

--------------------------------------------------------------------------------

N@veen
Blog : http://naveens-dotnet.blogspot.in/

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

//code behind
float percentage;
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

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