Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 693843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:47:43+00:00 2026-05-14T02:47:43+00:00

I coded some calculation stuff (I copied below a really simplifed example of what

  • 0

I coded some calculation stuff (I copied below a really simplifed example of what I did) like CASE2 and got bad results. Refactored the code like CASE1 and worked fine. I know there is an implicit cast in CASE 2, but not sure of the full reason. Any one could explain me what´s exactly happening below?

  //CASE 1, result 5.5
    double auxMedia = (5 + 6);
    auxMedia = auxMedia / 2;

    //CASE 2, result 5.0
    double auxMedia1 = (5 + 6) / 2;

    //CASE 3, result 5.5
    double auxMedia3 = (5.0 + 6.0) / 2.0;

    //CASE 4, result 5.5
    double auxMedia4 = (5 + 6) / 2.0;

My guess is that /2 in CASE2 is casting (5 + 6) to int and causing round of division to 5, then casted again to double and converted to 5.0.

CASE3 and CASE 4 also fixes the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:47:43+00:00Added an answer on May 14, 2026 at 2:47 am
    1. 5 + 6 is integer 11; which you then cast to double (in the assignment) and divide by two; 5.5
    2. 5 + 6 is integer 11; integer 11 / 2 = 5 under integer arithmetic, which you then cast to double (in the assignment)
    3. 5.0 + 6.0 is double 11.0; divide by double 2.0 giving double 5.5
    4. 5 + 6 is integer 11; there is an implicit cast to double 11.0 for the division, then divide double 2.0 giving double 5.5
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've coded some smaller projects using Silverlight 2.0, which is fairly impressive. Does Silverlight
I have coded some JavaScript to perform an ajax call in an asp.net application.
browsing some html code I find a text input coded as: <input type=text name=Email<%=orderRow.ID
I want to add some Ajax -niceness to my Django-coded website. In my Django
I'm having some wierd behaviour in my WinForm application coded in c#. in my:
it's been some time since I last coded in Java, but I need a
I have a data frame, and I want to do some calculation with existing
- (BOOL)coolMethod:(NSString*)str { //do some stuff Webservice *ws = [[WebService alloc] init]; NSString *result
I have some useful methods for physics calculations like acceleration / deceleration, speed, and
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.