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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:35:55+00:00 2026-06-13T08:35:55+00:00

Well I have been on this problem the entire day and I think that

  • 0

Well I have been on this problem the entire day and I think that qualifies the need for some help.

PHP

$hour1 = (float) $date1 / 10000;
$hour1 = (float) floor($hour1);

$hour2 = (float) $date2 / 10000;
$hour2 = (float) floor($hour2);

$minute1 = (float) $date1 / 10000;
$minute1 = (float) $minute1 - floor($minute1);
$minute1 = (float) $minute1 / 60;
$minute1 = (float) $minute1 * 100;

$minute2 = (float) $date2 / 10000;
$minute2 = (float) $minute2 - floor($minute2);
$minute2 = (float) $minute2 / 60;
$minute2 = (float) $minute2 * 100;

$date = (float) ($hour1 + minute1) - ($hour2 + minute2);
$date = floatval($date);

As you can see I’ve went a little overboard with the type casting.

Variable Values

$minute1 = .564478
$hour1 = 19

$minute2 = .9885546
$hour2 = 8

$date = (float) ($hour1 + minute1) - ($hour2 + minute2);

IS

$date = (float) (19 + .564478) - (8 + .9885546);

Now the result given is actually

11

AND NOT

10.575932......

Curiously, when I do this without variables echo (19 + .564478) - (8 + .9885546);… I get the floating point result of 10.575932.......

I understand that most programming languages round out floating points but I’ve tried everything including up to explicitly type casting. What is going on here?

  • 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-13T08:35:57+00:00Added an answer on June 13, 2026 at 8:35 am
    $date = (float) ($hour1 + minute1) - ($hour2 + minute2);
    

    Didn’t you forget about $ before minute1 and minute2 ??

    If you had, PHP would treat this vars as constans and count only $hour1 - $hour2 witch returns 11 in your case

    it should look like

    $date = (float) ($hour1 + $minute1) - ($hour2 + $minute2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer I am well aware that PHP might not have been the best choice
I have been trying to figure this out the ENTIRE DAY :( ... I
Similar questions have been asked but cannot find a solution that works well. What
I have a WCF service that I am consuming, and have been doing well
Can anyone help? I have been using the entity framework and its going well
I have been working on this problem for a while but still no joy.
I have been trying to solve this problem for three days now, it's really
I have been puzzling over a problem this morning with LinqToSQL. I'll try and
I have been having a small problem that I can't by-pass it, I keep
I'm aware that this question may have been asked before, but I still haven't

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.