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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:06:32+00:00 2026-05-23T04:06:32+00:00

quick question. Would this always be true? int i = …; double d =

  • 0

quick question.

Would this always be true?

int i = ...;
double d = i;
if (i == (int) d) ...

Or I need to do rounding to be sure?

if (i == Math.round(d)) ...
  • 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-23T04:06:33+00:00Added an answer on May 23, 2026 at 4:06 am

    Yes, all possible int values can round-trip to a double safely.

    You can verify it with this code:

        for (int i = Integer.MIN_VALUE; ; i++) {
            double d = i;
            if (i != (int) d) {
                throw new IllegalStateException("i can't be converted to double and back: " + i);
            }
            if (i == Integer.MAX_VALUE) {
                break;
            }
        }
    

    Note that I’m not using a normal for loop, because it would either skip Integer.MAX_VALUE or loop indefinitely.

    Note that the same is not true for int/float or for long/double!

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

Sidebar

Related Questions

Just a quick question about how you would go about implementing this. I want
Quick question. How would you refactor this Asp.net MVC 2 HtmlHelper? Specifically would it
Quick question; do I always need to check for a null value after performing
Quick question: Would it be a good or a bad idea to implement my
Question says it all. Some quick code examples of usage would be nice.. thanks!
Have a quick question about what would be the best way to implement iterators
Just a quick question on the iphone technology within this business card reader http://www.youtube.com/watch?v=F8z6pcxdrPo
I hope that this is a quick question to answer. I am developing a
Just a quick database design question: Do you ALWAYS use an ID field in
Quick question which I thought would be easily answered. I have a .net website,

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.