6 Years
Discussion Span
Last Post by gmahesh211

I don't really understand what you are trying to achieve. are you trying to find a percentage of a given number or are you trying to multiply a number by a percentage of another number?

A percentage is based on the number 100 and is just some number divided by 100...just rummage through your input and isolate any numbers with a %, drop the % symbol, divide the number by 100 and finish the rest of the math.

Your example of 10*100% is confusing though...you can't multiply 10 by 100% because the 100% is out of context. 100% of what? 50? 20? 3.14? I'd recommend you first find a different input method because the string you gave as an example doesn't make much sense...I'm assuming you want to find 100% of 10...which is 10 of course but let's say you want 50% of 10 instead...

The real math is 10*0.5 = 5...so, just isolate the percentage (50%) drop the % sign and divide 50 by 100 = 0.5 and then move on with the math 10*0.5.

Sorry if that doesn't make sense, but the example is a bit confusing to me.

Is this a console program or winforms? If it's a console it might be more difficult because you need to work with a string instead of having a input box. But I could be wrong...I don't like console programs...never made one.

Another consideration is multiple operators...what would your program do if given this: 10*100%*50? Just something to ponder...


Sir ,Permalink
(Please Check this code and find out what i am doing wrong)

        //    (Result Card)
        //   math+english+urdu

        private void btnsum_Click(object sender, EventArgs e)
            decimal mh = Convert.ToDecimal(txtMath.Text);
            decimal  en = Convert.ToDecimal (txtEnglish.Text);
            decimal  ur= Convert.ToDecimal(txtUrdu.Text);            
            decimal t = mh + en + ur;                
            lbltotal.Text = t.ToString();
            // Declare percentage 
             * when i want show percentage in label called lblpercentshow
             * it give error ( c# codeError 1   Cannot implicitly convert type 'decimal' to 'string)
            please send me code of percentage 
             * how can i get percentage in label1

            lblpercentshow.Text = t / 30 * 100;

Edited by Dani: Formatting fixed

decimal calculation = t/30*100;
lblpercentshow.Text = calculation.ToString();

You first have to convert your decimal to a string, before you can assign it to a string.


Oh Sir Permalink "?You solved my problem "I am very thanks full to You. you are so good
Thanks Thanks Thanks once again Thanks.I am very happy.This code wasted my 3 days.


Perhaps you could mark this thread as solved.

Kind regards and happy computing,
Sir ddanbe Permalink :)


am creating the two textboxes in c# enter the username&password that two textboxes to retrive the data through sql & check it correct/wrong
once correct open the windows form
wrong not open windows
please send me code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.