Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

percents and floating decimal points

Status
Not open for further replies.

Mokujin

Programmer
Dec 11, 2006
2
US
Ok here is my problem..here is a section of code in a program im trying to create -note this is my first program-

int firstlabel = 0;
double firsttextbox = 0;
double result = 0;
firstlabel = int.Parse(label1.Text);
firsttextbox = double.Parse(textBox1.Text);
result = firstlabel * firsttextbox;
label6.Text = result.ToString();


Now by looking at the code if
firstlabel = 400
and
firsttextbox = 50
the result would be 20,000
But what i am trying to do is make firsttextbox be a percent ie. i want the result to be 200 without the user haveing to input .50 in firsttextbox.
to clear it up a little if the user selected something and it displayed 400 in firstlabel then they inputed 50 in the first textbox i want it to do 400 * 50% and so far the only way i can get this done is by typing .50 in the firsttextbox.
Thanx for any help
 
Let me rephrase..
how would i
%
result = firstlabel - firsttextbox;

but i want firsttextbox to be a percent
so it would be firstlabel - a percent.
 
So if you have 100 in the label and the person types in 25 you want the answer to be 75?

result = label(100) - textbox(25%)
result = label(100) - (100 * .25)
result = 100 - 25
result = 75

if that's the case then your code would look something like:

double amt = Convert.ToDouble(firstlabel.Text);
doublc percent = Convert.ToDouble(firsttext.Text);

if ((percent < 1) && (percent > 0))
{
percent = percent / 100.00;
}

amt -= (amt * percent);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top