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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:35:01+00:00 2026-06-08T16:35:01+00:00

I’ve solved the problem I was having as described in this post but want

  • 0

I’ve solved the problem I was having as described in this post but want to understand the why of it (I spend a good amount of time figuring this out) as I’ve posed in the “Questions” below.

I had a problem with incrementing and decrementing the value returned when calling an IBAction method using UIStepper. When I ran and debugged the app I could step up and down and the log statements always reflected the intended stepper values but when I iteratively stepped up 0.1, 0.2 then 0.3 and then stepped down, when I got back to 0.0, when I performed the if test, the value for changeValue shown in the debugger was garbage and the test did not result in a true condition for == 0.0. Note that if I only stepped up to 0.2 then back down to 0.0, the if test for changeValue worked. It is only when I stepped up to 0.3 that I got the garbage value when I got back to 0.0.

Initially, to increment the stepper I set the stepValue property as:

viewStepper.stepvalue = 0.1

and the method returned the garbage value at 0.0 after stepping up to 0.3 and returning to 0.0.

When I changed the assignment to:

viewStepper.stepValue - 0.1f

problem solved – changeValue returns the intended 0.0 changeValue for my if test and the method works as intended regardless of the number of iterations.

Question: 1) I kind of get this but why if the stepValue is a double does the assignment value need to explicitly include the “f” and more curious to me 2) why did my test in the method work without the “f” when assigning the viewStepper.stepValue property when it did two step iterations, but returned garbage for changeValue when I did three iterations up and then returned back down to 0.0?

Here is the core of the method I was testing:

- (IBAction)doStepper:(UIStepper *)sender
{
   double changeValue = [sender value];
   NSLog(@"(double)change value %f", (double)changeValue);
   NSLog(@"sender value:%0.1f", [sender value]);

   if ((double)changeValue == 0.0) {
       if (!something) {
           // do stuff
       }
   // do stuff

   } else {
        // do stuff
   }
}
  • 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-08T16:35:04+00:00Added an answer on June 8, 2026 at 4:35 pm

    Sounds like a classic case of floating-point rounding error. The general rule is don’t compare floating point values for equality (==). In the second case you upped the precision of your number (to a double rather than the default single-precision float) so the integrity of your value lasted a few calculations longer. If you absolutely need to keep track of fine-grained exact decimal values, do one of the following:

    • Use the Decimal data type
    • Keep track of the underlying increment in an integer type but present it as a decimal. In your example, if your step is always 0.1 exactly, you could keep track of the number of steps as an integer but divide the number of steps by 10 to get the current useful value.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.