Jump to content


Check out our Community Blogs

hoser2001

Member Since 05 Jul 2006
Offline Last Active Jun 18 2008 06:46 AM
-----

Posts I've Made

In Topic: Convert any double to a fraction

23 May 2008 - 05:27 AM

what if I were to pass the result of 1 / 6 into the function? I tried convincing my computer that the value was indeed 1/6, but I don't think it is listening :(

In Topic: Convert any double to a fraction

21 May 2008 - 12:42 PM

I understand that... what I'm trying to figure out is how to get around this little problem... Anyone have any suggestions?

In Topic: beginners C# project

21 May 2008 - 10:12 AM

I suggest a trivial windows application such as a country club membership admin application, or a movie rental application. This way you can not only work on beginner level database development but also on an application that will offer the basics of the fundamentals of what all apps do, update, insert, delete and list.

Set up a database with customer tables, order tables, etc and an application with a few screens, or perhaps some form of tab control. All of the tools necessary to do this are free, visual studio and sql express. I'm sure you could even use visual studios built in tutorials utilizing the northwind database of sql server express.

In Topic: Convert any double to a fraction

21 May 2008 - 09:39 AM

Keep in mind all I want is a simple set of procedures that allows me to supply any double, and return a string variable in fraction form. What I have so far works for values like .4, .25, .75, etc... but when I try to perform the double equivalent of (1/6) the reduction process doesn't seem to work. Anyone have any idea?

alright this is what I have managed to piece together so far:
public string ConvertToFraction(double dValue)
        {
            string frac = String.Empty;

            try
            {
                if (dValue > 2147483647 && dValue < 1.0 / 2147483647)
                    frac = "not possible";
                if (dValue % 1 == 0)	// if whole number
                    frac = dValue.ToString();
                else
                {
                    double dTemp = dValue;
                    int iMultiple = 1;
                    string strTemp = dValue.ToString();
                    int i = 0;
                    while (strTemp[i] != '.')
                        i++;
                    int iDigitsAfterDecimal = strTemp.Length - i - 1;
                    while (dTemp * 10 < 2147483647 && iMultiple * 10 < 2147483647 && iDigitsAfterDecimal > 0)
                    {
                        dTemp *= 10;
                        iMultiple *= 10;
                        iDigitsAfterDecimal--;
                    }
                    int temp1 = (int)Math.Round(dTemp);//numerator
                    int temp2 = iMultiple;//denominator
                    frac = ReduceFraction(temp1, temp2);
                }
                return frac;
            }
            catch (Exception)
            {
                return frac = "oops";
            }
        }
        public string ReduceFraction(int Numerator, int Denominator)
        {
            try
            {
                if (Numerator == 0)
                {
                    Denominator = 1;
                    return Numerator.ToString() + "/" + Denominator.ToString();
                }

                int iGCD = GCD(Numerator, Denominator);
                Numerator /= iGCD;
                Denominator /= iGCD;

                if (Denominator < 0)	// if -ve sign in denominator
                {
                    //pass -ve sign to numerator
                    Numerator *= -1;
                    Denominator *= -1;
                }
                string temp1 = Numerator.ToString();
                string temp2 = Denominator.ToString();
                string frac = temp1 + "/" + temp2;
                return frac;

            } 
            catch (Exception exp)
            {
                return"Cannot reduce Fraction";
            }
        }
        private static int GCD(int iNo1, int iNo2)
        {
            // take absolute values
            if (iNo1 < 0) iNo1 = -iNo1;
            if (iNo2 < 0) iNo2 = -iNo2;

            do
            {
                if (iNo1 < iNo2)
                {
                    int tmp = iNo1;  // swap the two operands
                    iNo1 = iNo2;
                    iNo2 = tmp;
                }
                iNo1 = iNo1 % iNo2;
            } while (iNo1 != 0);
            return iNo2;
        }

In Topic: automate webBrowser navigation

06 September 2007 - 03:38 AM

the example you posted for mshtml is pretty much the exact same thing I just said doesn't work. The problem with that code is I dont know what "mybutton" is. The button doesn't have a name on the form.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download