Results 1 to 3 of 3

Thread: Simple DOuble to Integer Question.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Simple DOuble to Integer Question.

    Code:
    		
    int GambleCash = 1000;	
    double RandomGamble = Math.random(); 
    int GambleReturnCash = (((GambleCash * 1.5) - (GambleCash / 2) + 1) * RandomGamble) +(GambleCash / 2);
    And heres the error that i get.


    Im guessing its because RandomGamble is a double which is needed for Math.random because its random 0 to 1 so its decimals which needs double.

    so how can you change a double to an integer?

  2. #2
    Lively Member
    Join Date
    Dec 2005
    Posts
    68

    Re: Simple DOuble to Integer Question.

    Code:
    double value1 = 1.5;
    int value = (int)value1;
    value will be assigned the value of 1.
    When you explicitly cast a double to an int the fractional part gets truncated.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Re: Simple DOuble to Integer Question.

    it worked :!:!!:!:!: ty so much

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