I am developing a application that need to calculate percentage from two numbers. dotnet have some method for do this? i like to write this calculate by myself. but i don't good in mathematics unfortunately.
really, how to get percentage in mathematics? for example i have 10000 request in my application, and 400 request of them are for special part of my application. how to calculate what percent of request are request for a part of my application?
and how to calculate reverse, for example, i know 5 percent of users like my special post, how can calculate number of users that like that post?
Thank you and sorry for my bad English.
C# – how to get percentage of two numbers and calculate from a percentage
cmathnetpercentage
Related Topic
- C# – How to create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- C# – How to update the GUI from another thread
- C# – Get int value from enum in C#
- C# – Calculate difference between two dates (number of days)
- Javascript – How to perform an integer division, and separately get the remainder, in JavaScript
- C# – a NullReferenceException, and how to fix it
- C# – How and when to use ‘async’ and ‘await’
Best Answer
Since it's just arithmetic, every programming language has this. Generally, the calculation would be...
If you want to find "What percent of
Y
isX
?", such as "What percent of 100 is 50?", then you divideX
byY
:or:
Note, however, that in programming languages you do have to be concerned with data types. In C# for example, if
X
andY
areint
s then the result will be0
, not0.5
. This is because anint
divided by anint
is also anint
.In that case you'd need to cast them to something like a
double
to get sub-integer precision:That would just be the reverse. Consider the values that you do know:
Then the number of users who like the post is the percentage times the total:
or: