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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:03:05+00:00 2026-05-24T01:03:05+00:00

I can’t achieve rounding a float. Those calls all returns me 3.5999999 and not

  • 0

I can’t achieve rounding a float.

Those calls all returns me 3.5999999 and not 3.6 for theoTimeoutTrick and theoTimeout.
How may I achieve to get that 3.6 value, into NSString AND float vars ?

#define minTimeout 1.0
#define defaultNbRetry 5

    float secondsWaitedForAnswer = 20.0;
    float minDelayBetween2Retry = 0.5;

    int theoNbRetries = defaultNbRetry;
    float theoTimeout = 0.0;

    while (theoTimeout < minTimeout && theoNbRetries > 0) {
        theoTimeout = (secondsWaitedForAnswer - (theoNbRetries-1)*minDelayBetween2Retry) / theoNbRetries;
        theoNbRetries--;
    }

    float theoTimeoutTrick = [[NSString stringWithFormat:@"%.1f", theoTimeout] floatValue];
    theoTimeout = roundf(theoTimeout * 10)/10.0;
  • 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-24T01:03:06+00:00Added an answer on May 24, 2026 at 1:03 am

    From Rounding numbers in Objective-C:

    float roundedValue = round(2.0f * number) / 2.0f;
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setMaximumFractionDigits:1];
    [formatter setRoundingMode: NSNumberFormatterRoundDown];
    
    NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:roundedValue]];
    [formatter release];
    

    That will get you a rounded string. You can parse it back into a float I’m sure.

    Okay, here’s some test code and some results:

    NSLog(@"%f", round(10*3.56)/10.0);
        =>3.600000
    NSLog(@"%f", round(10*3.54)/10.0);
        =>3.500000
    NSLog(@"%f", round(10*3.14)/10.0);
        =>3.100000
    

    Okay, you know what? Your original code works as intended on my machine, OSX 10.6 and Xcode 4. How exactly are you seeing your output?

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

Sidebar

Related Questions

Can someone tell me why this is not displaying the form? If I go
Can somebody tell me how to get mod_rewrite to rename this: our-work-section.php?id=3&title=something to our-work-section/something/3
Can we close all known/unknown connections to database with the code? I'm using Access
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can i get the source code for a WAMP stack installer somewhere? Any help
can someone let me know What is a non-delegating constructor ? I tried to
Can anyone shed light on this for me? undefined method `first_name' for # Here
Can anyone offered syntax for a sql query that takes an already created table
Can anyone direct me to a good tutorial for sqlite browser. I cant seem
Can pointers be considered an efficient and semantic-wise data structure? How can it stackup

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.