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

  • SEARCH
  • Home
  • 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 4249042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:20:37+00:00 2026-05-21T04:20:37+00:00

Why we can not store the division result of two integers into the float

  • 0

Why we can not store the division result of two integers into the float variable ?

int a = 100;
int b =50;
float temp = b/a;

it gives t= 0 !

also i did

int temp = b/a;

it gives t= 0 !

but when I did

float temp = (float)b / (float)a;

it gives proper result. Why so ?

  • 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-21T04:20:38+00:00Added an answer on May 21, 2026 at 4:20 am

    The reason why float temp = b/a; gives 0 while float temp = (float)b/a; gives 0.5 is that the compiler determines the output type of the division operation based upon the types of the operands, not the destination storage type. Put simply:

    int   /   int = int
    float /   int = float
    int   / float = float
    float / float = float
    

    So when you do float temp = b/a; you’re doing in integer divide of b and a, and then storing the resulting integer (0 in your example) into a variable of type float. In essence, by the time the value is converted to floating-point you have already lost the information you are looking for (assuming you wanted to do a floating-point divide), and the conversion is not going to bring it back.

    In order to get the result you want (again, assuming that you want to do a floating-point divide), you need to cast at least one of the operands to float before you divide.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that returns two int Values. The first can not
Java collections only store Objects, not primitive types; however we can store the wrapper
I need some division algorithm which can handle big integers (128-bit). I've already asked
I know that stack size is fixed. So we can not store large objects
How can I store pairs of integers in a List? I know I could
I am using Datetime.Minvalue which return 1.1.0001. This value can not be stored to
Is there anyway I can execute stored procedure via EXEC (so not specifying CommandType.StoredProcedure
I have a general question and I'm not sure where to begin, literally. Can
I have a problem I can not solve, when the GPS data logger is
I'd like to not store times in my local timezone, but Sequel is making

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.