views:

29

answers:

1

I am developing an application i need to run my app both in 3.0 and 4.0. I have a textfield where when i try to enter numbers in the textfield the behaviour is like this... IN 3.0 :- It allows to enter 7 digits and 2 fractional values (I have formatted it like this). I have formatted and localized the numbers along with the comma seperations depending on the country selected. It is working perfectly in 3.0 and 3.1.2

IN 4.0 : - It allows you to enter only 4 numbers and after entering 5th digit it is making the textfields empty.. Nothing is displayed when u enter the 5th number and when u enter the 6th number it starts from the 1st number and continues the same til 4 numbers. ex: - when u enter 1234, textfield appears - 1234 and when u enter 12345, textfield appears " ". and when u enter 6 now it starts with 6 and so on..

I am using the NSNumberFormatter and numberfromstring method to format the values entered in the textfield.

I am not able to understand why this is happening like this... Please help me...

A: 

I gave some work-around on another question in this site. From what I can see the NSNumberFormatter sometimes has problems when the text has spaces or commas (eg every 3 digits). It returned NIL when it found a space. But, in another area of my code, it appeared to work OK

0

I had the same problem. I tracked it down to a NSNumberFormatter statement that did not like spaces (or commas) every 3 digits in the numbers. Which is one of the reasons for having a number formatter.

NSNumber *number = [currencyFormatter numberFromString:mstring];

It is fairly standard code in many examples on the internet, so I suspect a lot will find the problem.

Anyway, I fixed it by getting rid of the spaces

NSArray *sArray = [mstring componentsSeparatedByString:@" "]; [mstring setString:@" "]; //space at beginning is OK, would prefer nil for (NSString *sElement in sArray) { [mstring appendString:sElement]; }

Then the currencyFormatter line worked.

BUT, in another area of my code, that same currencyFormatter statement worked with no problem. I tried changing code in the area to cause the problem, but I could not.

So, very curious!!! Derek MakeItSoSudios.com