Problem with coercion of string to number, number formatter on TF

Hello,

I have been looking all day, tried a million thing, but I cannot find the reason why this doesnt work. I have an application that takes 3 Text Field’s values and does a calculation onto them. My problem is with one of them only. I have bound the value of this text field to a property in Xcode, and everything is fine until I attach a NSNumberFormatter onto it in Interface Builder. I need it formatted like this: “#,##0.00” and also localized, but if I try to coerce the contents to a number in AS, it gives me an error:

“Can’t make “29.79999923706055” into type number.”

The closest I have gotten to a solution looks like this:


set diagonalOfScreenValueTemp to (IBscreenDiagonalValue as string)
set fmt to current application's NSNumberFormatter's alloc()'s init()
tell fmt to setFormat_("#,##0.00")
set diagonalOfScreenValue to fmt's numberFromString_(diagonalOfScreenValueTemp)

What I need is a number in the AS world, not the Cocoa one.

The fact that this problem occurs only when there is a formatter attached to the field, I imagine that I have to read it back somehow through some kind of filter, and I thought that this code would do it, but nope.

Anyone has had this problem, or anyone has a lead to the direction I should take?

Thanks alot!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Have you tried coercing to a real?

Yep, same error, “Can’t make “29.79999923706055” into type real.”

It feels like when there is a Number formatter attached to the Text field it changes the kind of value stored in the binded variable… This has been the idea behind all my tries, but so far, no result. If the number is an integer, say 29, it doesnt create an error, odd…

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Found it… actually very stupid. I was doing this:

set diagonalOfScreenValue to (IBscreenDiagonalValue as string) as real

It turns out I don’t need to coerce it to a string first… A good night sleep makes all the difference!

Thanks!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)