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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:39:21+00:00 2026-05-23T13:39:21+00:00

Possible Duplicate: Java Integer Division, How do you produce a double? double wang =

  • 0

Possible Duplicate:
Java Integer Division, How do you produce a double?

double wang = 3 / 2;
Log.v("TEST", "Wang: " + Double.toString(wang));

Logcat output…

07-04 09:01:03.908: VERBOSE/TEST(28432): Wang: 1.0

I’m sure there’s an obvious answer to this and probably I’m just tired from coding all night but this has me stumped.

  • 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-23T13:39:22+00:00Added an answer on May 23, 2026 at 1:39 pm

    In many languages, Java being one of them, the way you write a number in an expression decides what type it gets. In Java, a few of the common number types behave like this1:

    // In these cases the specs are obviously redundant, since all values will be
    // cast correctly anyway, but it was the easiest way to show how to get to the
    // different data types :P
    int i = 1;
    long l = 1L;
    float f = 1.0f;   // I believe the f and d for float and double are optional, but
    double d = 1.0d;  // I wouldn't bet on what the default is if they're omitted...
    

    Thus, when you declare 3 / 2, you’re really saying (the integer 3) / (the integer 2). Java performs the division, and finds the result to be 1 (i.e. the integer 1…) since that’s the result of dividing 3 and 2 as integers. Finally, the integer 1 is cast to the double 1.0d which is stored in your variable.

    To work around this, you should (as many others have suggested) instead calculate the quotient of

    (the double 3) / (the double 2)
    

    or, in Java syntax,

    double wang = 3.0 / 2.0;
    

    1 Source: The Java Tutorial from Oracle

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

Sidebar

Related Questions

Possible Duplicate: What’s the reason I can’t create generic array types in Java? HashSet<Integer>[]
Possible Duplicate: Java - simple division in Java ---> bug/feature? anyone know bigdecimal in
Possible Duplicate: Why should the interface for a Java class be prefered? ArrayList<Integer> al
Possible Duplicate: In Java, can I define an integer constant in binary format? In
Possible Duplicate: Java floating point arithmetic What is special about this double math in
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: When to use “strictfp” keyword in java? What is the use of
Possible Duplicate: Weird Java Boxing Recently I saw a presentation where was the following

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.