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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:23:07+00:00 2026-05-25T10:23:07+00:00

I have a very simple division in Java (it’s a product quantity / production

  • 0

I have a very simple division in Java (it’s a product quantity / production per hour), however whenever I make this division I get strange errors:

float res = quantity / standard;

I have tried the above division with several values and I always get errors, however the one that I’ve tried everywhere else and gotten right was this:

Everywhere in the world:

13.6 = 6800 / 500;

Java:

13.0 = 6800 / 500;

I’ve researched BigDecimal and BigInteger, however I haven’t found a way to create this division with them, is there any other way to do this division in Java without having precision errors??

Any help will be greatly appreciated.

  • 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-25T10:23:08+00:00Added an answer on May 25, 2026 at 10:23 am

    You’re dividing integers, which means that you’re using integer division.

    In integer division the fractional part of the result is thrown away.

    Try the following:

    float res = (float) quantity / standard;
                ^^^^^^^
    

    The above forces the numerator to be treated as a float which in turn promotes the denominator to float as well, and a float-division is performed instead of an int-division.

    Note that if you’re dealing with literals, you can change

    float f = 6800 / 500;
    

    to include the f suffix to make the denominator a float:

    float f = 6800f / 500;
                  ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple Java RMI Server that looks like the following: import
I have very simple situation and really don't have a clue why this isn't
I have very simple query. I want to make sure that I don't have
I have very simple script for submitting the form. This is html template: <table>
I have a very simple command line Java application that I wish to port
i have this very simple php script: <?php require 'functions.php'; $token = some-number; $id
I have something very simple but I can not make it work correctly in
I have very simple data model like this: create table Company ( id int
i have very simple problem. I need to create model, that represent element of

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.