|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
convert an improper fraction to a mixed numberI am trying to crete a method that will convert an improper fraction to a
mixed number... I am not sure how about how to acomplish this. I know I can get the remainder with the modulus operator (%), but I am not sure how to get the quotent. any insight would be appreciated. thanks In article <34825ED0-64F0-4B31-A850-6096D08E8***@microsoft.com>,
"Jeff" <J***@discussions.microsoft.com> wrote: An example would be helpful. I think I know what you want but I am not > I am trying to crete a method that will convert an improper fraction to a > mixed number... > > I am not sure how about how to acomplish this. I know I can get the > remainder with the modulus operator (%), but I am not sure how to get the > quotent. > > any insight would be appreciated. sure, as it seems quite simple to me. Example
improper fraction: 8/5 convert to mixed number... divide the numerator (8) by denominator (5)... this gives a quotent of 1 and remainder of 3... the remainder is placed over the divisor (5) so... the answer is 1 3/5 However, using the arithmitic operators does not provide the answer of a mixed number. Dividing 8/5 produces 1.6. Using the mod operator only provides the remainder. I am a novice programmer so that I am probably missing a simple proccess Thanks Show quoteHide quote "Matthew Smith" wrote: > In article <34825ED0-64F0-4B31-A850-6096D08E8***@microsoft.com>, > "Jeff" <J***@discussions.microsoft.com> wrote: > > > I am trying to crete a method that will convert an improper fraction to a > > mixed number... > > > > I am not sure how about how to acomplish this. I know I can get the > > remainder with the modulus operator (%), but I am not sure how to get the > > quotent. > > > > any insight would be appreciated. > > An example would be helpful. I think I know what you want but I am not > sure, as it seems quite simple to me. > What types are you using to store your numerator and denominator? If
division yields 1.6 then you are perhaps using decimal, float, or double? There is no need to use these for fractions. (You would never want to have a fraction of 1.6 / 5, for example.) Use int or long for the types of your numerator and denominator. Division will then truncate, so 8 / 5 will give you 1, not 1.6. int numerator;
int denominator; .... int wholePart = numerator / denominator; numerator = numerator % denominator; you will now have a mixed number: whole part, numerator, and denominator. Incidentally, I built and entire Fraction class, with arithmetic
operations, normalization, etc, if it will help. Thanks for the feedback. I would be very greateful if you would share your
fraction class and any knowledge about dealing with fractions. I am somewhat of a novice programmer and could use advice. I read an interesting articles on codeproject.com (www.codeproject.com/csharp/Fractiion.asp)... however, this class does not deal with mixed numbers and always reduces fractions to improper fractions, if available. thanks, jeff reed 97***@verizon.net Show quoteHide quote "Bruce Wood" wrote: > Incidentally, I built and entire Fraction class, with arithmetic > operations, normalization, etc, if it will help. > >
Other interesting topics
COM Servers
Break out of Try Communicating between forms... C# Reflection - Nasty bug?? xpath in c# How do I change the radiobutton when listbox selection has changed If statement with multiple condition How to select treenode in treeview by name? HELP Problem serializing a structure Splitting a string array to seperate variables |
|||||||||||||||||||||||