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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:11:41+00:00 2026-05-19T12:11:41+00:00

Please check out this piece of code, more specifically the hourStep calculations. int h

  • 0

Please check out this piece of code, more specifically the hourStep calculations.

int h = [[timeArray objectAtIndex:0] intValue];
int m = [[timeArray objectAtIndex:1] intValue];
int s = [[timeArray objectAtIndex:2] intValue];
int mm = [[timeArray objectAtIndex:3] intValue];

NSLog([NSString stringWithFormat:@"time h:%d, m:%d, s:%d, mm:%d", h, m, s, mm]);
//time h:13, m:7, s:55, mm:105

float hourStep1 = m / 60;
float hourStep2 = h + hourStep1;
float hourStep3 = hourStep2 / 24;
float hourStep4 = hourStep3 * 15;

int hour1 = ceil(hourStep4);

NSLog([NSString stringWithFormat:@"hourStep1: %f, hourStep2: %f, hourStep3: %f, hourStep4: %f result: %d", hourStep1, hourStep2, hourStep3, hourStep4, hour1]);
//hourStep1: 0.000000, hourStep2: 13.000000, hourStep3: 0.541667, hourStep4: 8.125000 result: 9

float hourStep5 = ((h + (m / 60)) / 24) * 15; 
NSLog([NSString stringWithFormat:@"hourStep5: %f", hourStep5]);

//hourStep5: 0.000000

I have broken down the calculation into the various steps to get the correct answer but can anyone explain why hourStep5 doesn’t produce what hourStep4 produces?

  • 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-19T12:11:41+00:00Added an answer on May 19, 2026 at 12:11 pm

    It’s the difference between integer division and floating-point division.

    This line:

    float hourStep3 = hourStep2 / 24;
    

    evaluates to 13.0f / 24 which results in 0.541667f (floating-point division).

    In the combined calculation, you are only dealing with integers (without converting to floats in between), so

    (h + (m / 60)) / 24
    

    evaluates to 13 / 24 which equals 0 (integer division). Change it to

    (h + (m / 60)) / 24.0f
    

    and you will get the same result as above.

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

Sidebar

Related Questions

Please check this code out it compiles and runs absolutely fine.. The question is
Can someone please check out this code, i really dont understand why i got
Can some one please explain to me why this piece of code prints out
http://smiths-heimann.az/index.php?feat=1 please check out this page. My php code looks like that. <?php /*at
Please check out this issue: http://code.google.com/p/android/issues/detail?id=20791 The project (https://github.com/kaciula/BugRetain) uses a CursorLoader to take
Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
Please check this: http://img62.imageshack.us/img62/3598/ieff.png why is it more height than in FF.. i want
Please check out this http://jsfiddle.net/karthik64/JHVDn/1/ . Well I believe you got where I am
Could some on please check out this URL with Mozilla - http://smartplast.com/soon/ . As
Please check out this page: http://onomadesign.com/wordpress/identity-design/hans-appenzeller/ The thumbnails on the right, link to different

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.