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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:39:34+00:00 2026-05-29T06:39:34+00:00

I have the above code private float farenaitCelsiusMath(float f) { float result; result =

  • 0

I have the above code

private float farenaitCelsiusMath(float f) {

        float result;
        result = (f-1)*(2/3);
        return result;
    }

when i run the app on the emulator it evaluates to 0 whatever value i give to f.

But when the third line to result = (f-1)*2/3; it evaluates correctly.

Why does that happens? Is there sth i should know about arithmetic expressions in java?

  • 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-29T06:39:35+00:00Added an answer on May 29, 2026 at 6:39 am

    Because (2/3) is INTEGER division, which evaluates to 0 since integer division truncates.

    • (f-1) is FLOAT since f is FLOAT
    • (2/3) is INTEGER value 0 since integer division truncates
    • (f-1)*(2/3) is FLOAT since (f-1) is FLOAT, and value 0 because anything times 0 is 0.

    When it’s (f-1)*2/3 then it evaluates as

    • (f-1) is FLOAT since f is FLOAT;
    • (f-1)*2 is FLOAT since (f-1) is FLOAT
    • (f-1)*2/3 is FLOAT since (f-1)*2 is FLOAT

    To get what you expect, make it (2./3) or (2/3.) — both are promoted to FLOAT because of the decimal point– or even better make it explicit with a cast ((float)2/(float)3). This doesn’t cost anything at run time, it’s all done by the compiler.

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

Sidebar

Related Questions

<p><span class=linky><a href=deletephone.php?id=' . $row['id'] . '>Delete Phone</a></span></p><br /> I have the above code
my $str=1:2:3:4:5; my ($a,$b)=split(':',$str,2); In the above code I have used limit as 2
I have no code behind and the above error keep prompting on INSERT. The
I was looking at some code: @interface ClassName (Private) - (float)methodOne:(NSDictionary *)argOne; - (void)methodTwo:(NSDictionary
I can't seem to run the following code in Eclipse. I do have a
Suppose that I have the following code: private void UpdateDB(QuoteDataSet dataSet, Strint tableName) {
private void btnBrowserGo_Click(object sender, EventArgs e) { browser.Navigate(txtBrowserURL.Text); } The code above directs the
i have executed the following code public class Activity_Threads_Handler extends Activity { private int
I have a sample code below. #include<iostream> template<typename T> class XYZ { private: T
Code: private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { updateTickCounter(slider1.Value); } private void updateTickCounter(double value)

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.