Results 1 to 3 of 3

Thread: [2.0] is this bug in C#?

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    [2.0] is this bug in C#?

    Hi,
    I have 2 codes below which is almost the same but with difference answer.

    Anyone can explain?

    PHP Code:
    double score;
    score 9.00 
    score = 1.8
    vs
    PHP Code:
    double score;

    score  
    score =1

    thanks,
    Popskie

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] is this bug in C#?

    The difference lies in which division operator is called. In the first example the operator is /(double,int) which performs a floating-point division and returns a double, thus preserving the fraction. In the second example the operator is /(int,int) which performs an integer division thus discarding the fraction part. The result is then coerced to a double as per your variable type.

    See also: C# Numeric Literals

  3. #3

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