Results 1 to 4 of 4

Thread: Problem with numbers in Variable

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Problem with numbers in Variable

    hi all

    I think im on the last leg of my poject here. I created a program to take a number and convert it into two "random" points that can be converted back to text later


    the problem that im running into is that it works for short numbers (i havent finished the text to number part) so i can get about 7 digits in and then it will crash out



    another problem i get is when i output numbers by useing the .tostring() i have been getting Scientific notation for output and i just need straight numbers

    anyone know how to turn something like that off?


    vb Code:
    1. Random random = new Random();
    2.           float X1, X2, X3, Y1, Y2, Y3;
    3.           //STEP3 MAKE RANDOM PNT1
    4.           X1 = random.Next(2,10000);
    5.           Y1 = random.Next(2,10000);
    6.  
    7.           //STEP2 MAKE PNT2 WITH CONSTANT ( FROM TEXT BOX)
    8.           X2 = Convert.ToInt64(textBox7.Text);
    9.           Y2 = 0;
    10.  
    11.           X3 = 1;
    12.           Y3 = 1;
    13.  
    14.           //STEP4 GET SLOPE FROM PNT1 AND PNT2
    15.           float slope = (Y2 - Y1) / (X2 - X1);
    16.           float t = random.Next(2,10000);
    17.  
    18.           //STEP5 GET RANDOM POINT ALONG LINE MADE PNT1 AND PNT2
    19.           X3 = t + X2;
    20.           Y3 = t * slope + Y2;
    21.  
    22.           //float p = random.Next(1);
    23.           //  X3 = X1+(1-p)*X2;
    24.           //  Y3 = p * Y1 + (1 - p) * 2;
    25.  
    26.           //OUTPUT TO TEXTBOX
    27.           textBox5.Text = t.ToString();
    28.           textBox6.Text = slope.ToString();
    29.  
    30.           textBox1.Text = X1.ToString();
    31.           textBox2.Text = Y1.ToString();
    32.  
    33.           textBox3.Text = X2.ToString();
    34.           textBox4.Text = Y2.ToString();
    35.  
    36.           textBox9.Text = X3.ToString();
    37.           textBox8.Text = Y3.ToString();

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Problem with numbers in Variable

    What kind of error do you get when it crashes?

    To adjust your output to strings, you can use:

    Code:
    .ToString("F12")
    Where the 12 in this case represents the number of places after the decimal point.

    Here is a pretty good description on the tostring method:

    http://www.blackwasp.co.uk/CSharpNumericToString.aspx

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Problem with numbers in Variable

    some times its decimal some times its just a large int.

  4. #4
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: Problem with numbers in Variable

    it sounds like to me it is scientific notation because it is a large decimal. you could use something like

    decimal.toInt32(variable);

    or

    set the number of decimal places.

    if you want to get rid of the decimal all together i would use the

    decimal.toInt32()

    -zd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width