Results 1 to 4 of 4

Thread: Converting Double to Int32

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    53

    Converting Double to Int32

    when trying to convert a double to an integer, it always rounds up. Say I divide 2 numbers and get .8, it returns one, so what it the code to make it not round up, to return 0 instead? So whats the code to make it return 0, or is there?

  2. #2
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Re: Converting Double to Int32

    when trying to convert a double to an integer, it always rounds up. Say I divide 2 numbers and get .8, it returns one, so what it the code to make it not round up, to return 0 instead? So whats the code to make it return 0, or is there?
    I just tried this:

    Code:
    	int x = (int)(double).8;
    	MessageBox.Show(x.ToString());
    And it returned 0.

    Dan

  3. #3
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: Converting Double to Int32

    You might want to take a look at System.Math.Floor and System.Math.Ceiling functions.
    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    53

    Re: Converting Double to Int32

    ok thanks for the help guys =)

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