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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:22:24+00:00 2026-06-05T23:22:24+00:00

I have trouble figuring out why a simple division like this one always returns

  • 0

I have trouble figuring out why a simple division like this one always returns 0.

System.out.println(4091365376L / 4091495462L * 100L);

I suffixed all numbers with Ls so they’re treated as Longs. I keep getting a zero.

I’m trying to calculate the percentage of 4091365376L to 4091495462L. My values are Longs but I’m just looking for a simple Integer value.

  • 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-05T23:22:26+00:00Added an answer on June 5, 2026 at 11:22 pm

    You are a victim of integer rounding (actually: truncation). Try this:

    System.out.println(4091365376L * 100L / 4091495462L);
    

    Prints 99. Or cast to double implicitly:

    System.out.println(100.0 * 4091365376L / 4091495462L);
    

    Giving 99.99682057572328. Your problem is that 4091495462L is slightly bigger than 4091365376L so when diving them, the result is truncated to 0 (try 3 / 4, if you are not convinced). and 0 times 100 is…

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

Sidebar

Related Questions

Ok I am having trouble figuring out how to approach this. I have a
I'm having trouble figuring this out. If I have a checkboxlist inside a usercontrol,
I'm having some trouble figuring this out. I have an unordered list menu that
I’m having a little trouble figuring this one out. I’m fairly new to C#,
I have a simple set of data that I am having trouble figuring out
It seems that this should be simple, but I'm having trouble figuring out how
I'm having some trouble figuring out to call methods that I have in other
I am running into an error I am having trouble figuring out. I have
I have a seemly simple question with SQL that I am having trouble figuring
I have a exceedingly simplistic data model (below). I am having trouble figuring out

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.