Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > setFloatValue and NSTextField

setFloatValue and NSTextField
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2006
Location: London, UK
Status: Offline
Reply With Quote
Dec 7, 2007, 01:17 PM
 
Hi,

I've got a text field where you put a float value into, and then it is passed it to a float variable. I then put that float variable (using setFloatValue to a NSTextField (a label). It ALWAYS comes out as some very long decimal number

Is there any way I can use what was entered exactly instead.

It needs to be a float value as it is also being passed to an OpenGL script.

Thanks
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 7, 2007, 01:40 PM
 
It sounds like you're running into the imprecision of floats. Not every number can be precisely represented by the floating point specification, so you might get the closest approximation that can be represented. This is why testing for equality between floats is a bad idea.

If the number is not even close, something else is going on and you'll need to be more specific, I think.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Fresh-Faced Recruit
Join Date: Aug 2006
Location: London, UK
Status: Offline
Reply With Quote
Dec 7, 2007, 05:10 PM
 
The number is close (sort of), but is there any way I can round it, at all? Like some maths or something, or a function built into Cocoa?

Thanks
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 7, 2007, 07:29 PM
 
I think what you want is an NSNumberFormatter.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 09:35 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2