i want the result of an equation rounded to the nearest integer. e.g.
137 * (3/4) = 103
Consider the following incorrect code.
int width1 = 4; int height1 = 3; int width2 = 137; int height2 = width2 * (height1 / width1);
What is the proper way to perform ‘integer’ math in C#?
Do i really have to do:
int height2 = (int)Math.Round( (float)width2 * ((float)height1 / (float)width1) );
As said above, you should do the multiplication before the division. Anyway you could write your expression with casting only the divisor: