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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:44:54+00:00 2026-05-12T11:44:54+00:00

I have an iPhone app. I am storing a float value, (distance), in my

  • 0

I have an iPhone app. I am storing a float value, (distance), in my sqlite3 db. (The field in the db is formatted to float) I am able to store float values correctly in the db no problem. However, I can’t seem to figure out how to pull the value back out of the db the format and present it correctly. Here is my code for pulling the value out of my db and using it:

NSString *itemDistance = [NSString stringWithFormat:@"%f",[item distance]];
float questionDistance = [itemDistance floatValue];

[item distance] is a float value. I can’t get this to work. I get a REALLY long value instead. What am I doing wrong? Any help would be greatly appreciated.

Thank you in advance for your help,

L.

  • 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-12T11:44:55+00:00Added an answer on May 12, 2026 at 11:44 am

    Assuming your -distance method is returning the right value, then this sounds like basic misunderstanding of how floats work in C. Common mistake. Every developer falls into this trap at least once.

    Floating point numbers can actually only represent a fairly limited number of values. Specifically, unless you happen to choose a value that is exactly representable as a float, you’ll get the nearest value, which will often have many decimal places of data.

    The reason for this is because a float is only 32 bits; 4 bytes. Now, how many numbers with decimal points are there between 0..1000000 or 0..1000 or, even, 0..1. Infinite. Floats implement a very finite subset of possible numeric values and do so in a way where the resulting possible values may have many decimal places.

    Consider:

    printf("%5.18f\n", (float) 2.05);
    printf("%5.18f\n", (float) 2.45);
    printf("%5.18f\n", (float) 4200.75);
    printf("%5.18f\n", (float) 37.89);
    printf("%5.18f\n", (float) 1.2);
    printf("%5.18f\n", (float) -1.2);
    

    This prints:

    2.049999952316284180
    2.450000047683715820
    4200.750000000000000000
    37.889999389648437500
    1.200000047683715820
    -1.200000047683715820
    

    Those values are as close to the values in the bit of code that a float could represent.

    If you need more precision, use a double. More precision than that? Use NSDecimalNumber.

    And, if you can, use CoreData. It makes managing this kind of thing a bit more straightforward.

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

Sidebar

Related Questions

I'm developing my first iPhone app, and while implementing user preferences, I have a
I am building an iphone app and would like to keep track of how
I am a beginner to iPhone App development. Please help me out. In my
A bit of background: I am building an iPhone app with a complementary server
Let's say I need to access a web service from an iPhone app. This
i've been making web app's and working with various server side language like php,
I am trying to call a session based webservice from my Iphone application. However,
As a follow up to this previous question , I have a Core Data-based
I have an application that supports iOS 2.x. I am about to revamp this

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.