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

  • Home
  • SEARCH
  • 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 6679675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:10+00:00 2026-05-26T04:23:10+00:00

I export some floatvalues into a Textfile (JSONFormat) then import it again into my

  • 0

I export some floatvalues into a Textfile (JSONFormat) then import it again into my project. Weirdly, the NSNumberformatter takes the Strings and adds some random(?) decimal places on its own….

This is what I get from NSLog:

[9697:207] f1 150.837296   -  f2 150,8373 
[9697:207] f1 160.746902   -  f2 160,7469
[9697:207] f1 150.242599   -  f2 150,2426
[9697:207] f1 160.068893   -  f2 160,0689
[9697:207] f1 149.451096   -  f2 149,4511
[9697:207] f1 159.154205   -  f2 159,1542

As you can see, the values to the right are my input strings(f2) and the values to the left are my floats (f1).

Heres my code:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setDecimalSeparator:@","];

float f1 = (float)[[formatter numberFromString:[mutableArray objectAtIndex:i]] floatValue];

Any ideas why this is happening?

  • 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-26T04:23:11+00:00Added an answer on May 26, 2026 at 4:23 am

    Cause of this effect is in float type, because float is imprecise type.

    See examples below:

    NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    [formatter setDecimalSeparator:@","];
    
    float f1 = [[formatter numberFromString:@"150,8373"] floatValue];
    NSLog(@"%.8f", f1); //150.83729553
    NSLog(@"%.4f", f1); //150.8373 - formatting hides a tail
    
    double f1 = [[formatter numberFromString:@"150,8373"] double];
    NSLog(@"%.8f", f1); //150.83730000
    

    So, use double for getting right precision.

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

Sidebar

Related Questions

Some servers only support ftp to upload files. When I export the a project
I'm trying to export an Excel database into .txt (Tab Delimited), but some of
In my application iOS I need to export some data into CSV or HTML
to export some data i want to be able to generate an html output.
I am trying to export some prepared assets out of Expression Design 2 and
I would like to export some macros that I have defined and be able
I am working on a feather that export some tables(~50) to a disk file
I have this application I'm developing in JSP and I wish to export some
I have some Perl modules which exports various functions. (We haven't used @EXPORT in
I have an Excel table with some data that I would like to export

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.