Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-26-2011, 09:12 PM   #1 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default [textfield.text floatValue] returns incorrect float value

Whenever the textfield contains 9 or more numbers, [textfield.text floatValue] will return a number with the first 7 numbers correct, but the last 2 wrong. For example, say I type 987654321 into the textfield. It will show in the actual textfield that I type 987654321. However, [textfield.text floatValue] will return something to the effect of 987654336. Why is this? Here is some code:


Code:
-(IBAction)numberOneKeyPressed {
//If the textfield isn't empty
        if([textField.text length] != 0) {
//And if the textfield has less than 9 numbers
            if([textField.text length] < 9) {
//Add a 1 to the end of the previous textfield value
                    textField.text = [NSString stringWithFormat:@"%.0f1",textFieldFloatValue];
//And assign the textfield floatvalue to the float variable
                    textFieldFloatValue = [[textField text] floatValue];
            }
        }
//if the textfield was empty to begin with
 else {
//just make the textfield say 1
            textField.text = [NSString stringWithFormat:@"1"];
//and assign the floatvalue to the float variable
            textFieldFloatValue = [[textField text] floatValue];
        }
//The NSLog here returns the incorrect value therefore showing me that the float variable is incorrect as well
    NSLog(@"%.0f",[[textField text] floatValue]);
}
As you can see, I have created a custom keyboard dealing with numbers. The method I provided you with is what is called when the user press the 1 button on the custom keyboard. Of course, I have the methods for the other numbers as well, but they are pretty much duplicates of this method, but substituting the correct numbers depending on which key is pressed. It works completely fine until the 9th number. Any ideas as to what's going on? Thanks in advance.
Whitehk is offline   Reply With Quote
Old 04-26-2011, 11:51 PM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Try replacing floatValue with doubleValue to see if that helps.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 04-27-2011, 07:53 AM   #3 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
Try replacing floatValue with doubleValue to see if that helps.
Thank you! This was part the problem. What I ended up doing was converting everything that had to do with floats to doubles, and instead of saying [[textfield text] doubleValue] I needed to change it to say [textfield.text doubleValue]. I wasn't sure why that was a problem too, but it was fixed once I did both of those things. Again, thanks.
Whitehk is offline   Reply With Quote
Old 04-27-2011, 08:13 AM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Hmm... I'm not sure what difference that could have made. textfield.text and [textfield text] are the same thing. The dot notation was introduce in ObjC v2 as a convenience to those more familiar with it but it translates to the same thing.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
custom keyboard, float, floatvalue, textfield.text, uitexfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 346
12 members and 334 guests
dansparrow, iOS.Lover, lorrettaui53, MikaelBartlett, Nobbsy, oztemel, pbart, PlutoPrime, samdanielblr, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,897
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0