Worker percent in C #

I have two values ​​with a decimal value and another value with a value that will calculate the percentage of this decimal value for example:

60% of 10 = 6

decimal value1 = 10; decimal percentage = 60; textbox1.text = ("mathsum here").toString(); 

How would you calculate this value using a decimal value and a value containing a percentage value?

+7
source share
10 answers
 number * percentage / 100 

So

 10 * 60 / 100 = 6 
+22
source

Perhaps this will help you think about it this way.

  6
 - = .6 (or equivalent to your 60%)
 10

In your example, you would like to know how to calculate the numerator (6), so assign a variable to it. Let X.

  X
 - = .6
 10

.. and solve for X by multiplying both sides by 10 (in your case).

  X * 10 = .6 * 10
 ------
   10

 X = .6 * 10

From this, I hope you can see that you can take a percentage value and multiply it by a "decimal" value.

Note that to get .6 you will need to convert your percentage (60) by dividing it by 100.

So our final formula is:

  60
 --- * 10
 one hundred 

or using variables:

  percentage
 ---------- * value1
    one hundred

I hope I added to your understanding, even if my formula is similar to the previous answers. I wanted to make sure that you understood how the formula was obtained.

Good luck

+7
source
 var result = (percentage/100) * value1; textbox1.Text = result.ToString(); 
+5
source

Do you mean this?

 textbox1.text = (value1 * percentage/100).ToString(); 

By the way, toString written toString in C # with capital T.

+3
source
 var answer = value1 * (percentage/100); 
+3
source

It wouldn't be easy

 percentage/100m*value 

?

+1
source

I would share the problems:

  • Calculate part of your original decimal place:

    decimal result = (value * percent) /100.0;

  • Provide the appropriate formatter to display the result as a percentage:

    text = result.ToString ("0.0%");

http://www.dotnetperls.com/percentage

+1
source

To get a percentage

 decimal Value = 1200; int percentage = 20; //20% var result=(percentage/100)*(Value); 
+1
source

You need to divide by 100.

60% = 60/100.

0
source

from the question he himself the answer is clear

60% means 60/100, then calculates it with a value

60/100 * 10 = 6 use logic for variables

  textbox1.Text = ((percentage /100) * value).ToString(); 

or

  textbox1.Text = ((percentage * .01 ) * value).ToString(); 
0
source

All Articles