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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:41:39+00:00 2026-06-07T09:41:39+00:00

I have a text field in an xib file. In a method in the

  • 0

I have a text field in an xib file. In a method in the .m file, I can print the contents of the text field, but I cannot get those contents converted to a float. The text field is formatted with commas, as in 123,456,789. Below is the code snippet, where datacellR2C2 is the textfield.

float originalValue2 = originalValue2 = [datacellR2C2.text  floatValue];
NSLog(@"datacellR2C2 as text --> %@ <---\n",datacellR2C2.text);  // this correctly shows the value in datacellR2C2
NSLog(@"originalValue2 = %f  <--\n", originalValue2);  // this incorrectly returns the value 1.0 

I would appreciate any suggestions for a fix or a direction where I should look for the problem.

  • 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-07T09:41:40+00:00Added an answer on June 7, 2026 at 9:41 am

    In the declaration for -floatValue a comment is shown:

    /* The following convenience methods all skip initial space characters
    (whitespaceSet) and ignore trailing characters. NSScanner can be used
    for more “exact” parsing of numbers.
    */

    Ergo, commas cause truncation, because they are trailing chars. Even the string you provided (123,456,789) only prints 123.000, because that’s all -floatValue sees.

    //test
    NSString *string = @"123,456,789";
    float originalValue2 = [string  floatValue];
    NSLog(@"datacellR2C2 as text --> %@ <---\n",string);  // this correctly shows the value in datacellR2C2
    NSLog(@"originalValue2 = %f  <--\n", originalValue2);
    
    //log
    2012-07-07 22:16:15.913 [5709:19d03] datacellR2C2 as text --> 123,456,789 <---
    2012-07-07 22:16:15.916 [5709:19d03] originalValue2 = 123.000000  <--
    

    Just get rid of them with a simple +stringByReplacingOccurrencesOfString:withString:, and remove those trailing commas:

    //test
    NSString *string = @"123,456,789";
    NSString *cleanString = [string stringByReplacingOccurrencesOfString:@"," withString:@""];
    float originalValue2 = [cleanString  floatValue];
    NSLog(@"datacellR2C2 as text --> %@ <---\n",cleanString);  // this correctly shows the value in datacellR2C2
    NSLog(@"originalValue2 = %f  <--\n", originalValue2);
    
    //log
    2012-07-07 22:20:20.737 [5887:19d03] datacellR2C2 as text --> 123456789 <---
    2012-07-07 22:20:20.739 [5887:19d03] originalValue2 = 123456792.000000  <--
    

    By the way, a float is rounding that string up to an even number, use double precision instead.

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

Sidebar

Related Questions

I have a text field that can be 30 characters in length, however it
For example: In my table I have text field with following text: The quick
I have a text field. If it has wrong values then it may show
i have a text field in Contact screen and the user need to enter
I have a text field that is near the bottom of the screen. When
I have a text field and am looking to have if be valid for
I have a text field that is a date, although sometimes it also has
I have a text field whose length I would like to limit at the
Hi I have a text field which I would like to bind to a
I'd like to have a text field like the expression editor text field in

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.