Calculate a Ratio in C#
I thought this would be simple, but searching Google didn't seem to help. I'm basically trying to write a function which will return a ratio as a string (eg 4:3) when supplies with two integers (eg 800 and 600). string GetRatio(Int A, Int B) { // Code I'm looking for return Ratio; } Konrad Rudolph You can simplify fractions by dividing numerator and denominator by their GCD : var gcd = GCD(A, B); return string.Format("{0}:{1}", A / gcd, B / gcd) And a very basic function for calculating the GCD, using the Euclidean algorithm : static int GCD(int a, int b) { return b == 0 ? Math.Abs(a) : GCD(b,