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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:43:33+00:00 2026-06-15T07:43:33+00:00

When I divide 317 by 219 in Java using doubles I get 1. For

  • 0

When I divide 317 by 219 in Java using doubles I get 1.
For example:

double b = 317/219;
System.out.println(b);

Output is: 1.

Is this because it is a recurring decimal?
Have had to use BigDecimal instead which is annoying.

  • 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-06-15T07:43:36+00:00Added an answer on June 15, 2026 at 7:43 am

    Try this

     double b = 317/219D;
    

    The default type of coded numbers in java is int, so with the code as you have it java is working with two int numbers and the result of the division would then be int too, which will truncate the decimal part to give a final result of 1. This int result is then cast from int 1 to a double 1 without a compiler warning because it’s a widening cast (one where the source type is guaranteed to “fit” into the target type).

    By coding either of the numbers as double with the trailing D (you may also use d, but I always use upper case letters because L as lowercase l looks like a 1), the result of the division will be double too.

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

Sidebar

Related Questions

How do you divide two integers and get a double or float answer in
How do I divide two integers to get a double?
Any possibility to divide a class into multiple physical files using Java?
When I divide two diffrent variables, I get this returned: 1.4007342235591407 but what I
I want to divide a number of type double, by an int. I only
Is it possible to divide a function into sections, something like this? Function myFunc
So I need to divide array value with array value. I'm using float multi-dimensional
I would like to divide my Qt project into several directories because it is
I'm trying to divide a string into parts for reading Roman numerals. For example
I have to divide the rows equally, so here, for example, there are 15

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.