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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:39:40+00:00 2026-06-01T15:39:40+00:00

If I invoke this method with different dates, the decimal places of the result

  • 0

If I invoke this method with different dates, the decimal places of the result of difference / 1000L / 60L / 60L / 24L will always be truncated. What can I do to prevent that? I need a result of 4.xx.

public boolean checkDelayed(Date date1, Date date2)
{
    long difference = date2.getTime() - date1.getTime();

    if (difference / 1000L / 60L / 60L / 24L <= 4L)
    {
        return true;
    }

    return false;
}
  • 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-01T15:39:42+00:00Added an answer on June 1, 2026 at 3:39 pm

    Try using doubles instead of Longs.

    public boolean checkDelayed(Date date1, Date date2)
    {
        double difference = (double) (date2.getTime() - date1.getTime());
    
        if (difference / 1000d / 60d / 60d / 24d <= 4d)
        {
            return true;
        }
    
        return false;
    }
    

    The best way would be to apply simple math. Your condition is this:

    difference / 1000L / 60L / 60L / 24L <= 4L
    

    Work out like this:

            difference / 60L / 60L / 24L <= 4000L
                  difference / 60L / 24L <= 240000L
                        difference / 24L <= 14400000L
                              difference <= 345600000L
    

    There you have it. The always working simple condition.

    public boolean checkDelayed(Date date1, Date date2)
    {
        long difference = date2.getTime() - date1.getTime();
    
        if (difference <= 345600000L)
        {
            return true;
        }
    
        return false;
    }
    

    The reason for all of this is that the long datatype does not support decimal values. By converting to a double you will be able to keep the decimal values.

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

Sidebar

Related Questions

Till this moment I used this method to invoke: public string AddText { set
Here's my extension method for invoke on a control: public static void Invoke<T>(this T
Is there any essential difference between this code: ThreadStart starter = new ThreadStart(SomeMethod); starter.Invoke();
I asynchronously invoke a method with Spring, using @Async . This method invokes another
I am trying to invoke ExecuteNonQuery() method of two different objects of OracleCommand class.
Normally we have to do like this to invoke a function from a function
Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
I am trying to use Desktop .browse() to invoke a URL, this works fine
So I have this method that get executed repeatedly public static boolean isReady(String dirPath,
In this article: http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx The author uses the following method to make thread-safe calls

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.