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 6064795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:19:10+00:00 2026-05-23T09:19:10+00:00

For the computation involving multiple types of variables, such as integer and double, is

  • 0

For the computation involving multiple types of variables, such as integer and double, is the following approach the correct way in terms of not causing any hidden error or information lost?

    int a = 2;
    double b = 3.0;
    double c;
    c = (double)(a+b);
    c = (double)(a/b);

Another scenario is that:

int x =2;
int y = 3;
double z;

z=x/y will not give me correct value like 0.666666666, how to handle this kind of scenario?

  • 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-23T09:19:10+00:00Added an answer on May 23, 2026 at 9:19 am

    When you perform an operation between a float and a integer, the result is a float. In general, the result will be the larger data type. What you are doing in the first place is correct if you want decimal precision. You don’t need the cast, even.

    In the second case, you can do several things

    z = x/(y*1.0) // convert the variable upon calulation
    

    or

     float x =2; // convert the variable itself
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I define the sequence of all natural numbers in the following way:
In computation theory are the terms Provable and Decidable interchangable? Do they mean the
I have an Interface called IStep that can do some computation (See Execution in
Why is the Pseudo header prepended to the UDP datagram for the computation of
I'm currently implementing a raytracer. Since raytracing is extremely computation heavy and since I
Not a competition, it is instead me trying to find why a certain regex
I get the following compilation error: error: expected `;' before 'it' Here's my code:
I'm making a code that is similar to this: #include <stdio.h> double some_function( double
I really like the way padrino 'just works' with compass but I have a
I have a computation task which is split in several individual program executions, with

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.