Multiplying

Post your questions regarding programming in C# in here.
3 posts Page 1 of 1
Contributors
User avatar
hortencio
New Member
New Member
Posts: 19
Joined: Thu Apr 19, 2012 1:41 am

Multiplying
hortencio
Hello,

I need to multiply 2 numbers. The first is a Quantity the second is thr price and i want the result in the fild Total. Once i type those numbers i need to calculate without pressing any button only by leaving the field. How can i do?

And then i would like to calculate subtotal, any % of that subtotal and then get the total.

C#
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Multiplying
MrAksel
In a field, do you mean TextBox? You could calculate each time the text changes:
Code: Select all
private void TextBox_TextChanged(object sender, System.EventArgs e) 
{
    int x = 0;
    int y = 0;
    int.TryParse(textBox1.Text, out x);
    int.TryParse(textBox2.Text, out y);
    textBox3.Text = (x * y).ToString();
    //Here is how to get 35% of the total. To get 12%, replace 0.35 with 0.12. 6% = 0.06
    textBox4.Text = (x * y * 0.35).ToString();
}
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
DreadNought
VIP - Donator
VIP - Donator
Posts: 116
Joined: Fri Jan 08, 2010 12:37 pm

Re: Multiplying
DreadNought
You should be using a ulong so most if not all number's will work fine.

If they could contain decimals you the decimal data type.
Bound and boom tech,
The Future Of Coding
3 posts Page 1 of 1
Return to “General coding help”