views:

46

answers:

2

I have set up a nice NSNumberFormatter which does all the things I want, except allowing a number to be preceded by a unary "+". It's not a common usage normally, but I'm entering latitudes and "+12.34" is sometimes used to indicate a northern latitude in the same way "-43.21" indicates southern. Likewise for longitudes and East/West. It may not be used every time but I don't want to make it 'illegal' -- that just annoys people.

I tried [... setLenient:TRUE] but that doesn't change this behavior.

I'm trying to not set up my own format string to avoid impacting localization.

Any suggestions?

A: 

How about putting a wrapper around the function which either strips the + or outputs it (I can't tell which conversion you're doing) as you expect it?

wallyk
That's what I did; it's easy and works.
Gavin Eadie
+1  A: 

Just a guess, but what happens if you use setPositivePrefix:?

[formatter setPositivePrefix:@"+"];
dreamlax
Brilliant! That does *exactly* what I want. Reminder to self: learn all the nooks and crannies of the NumberFormatter API !! Thanks.
Gavin Eadie
Darn! Sadly, in my excitement I didn't do a very good test. Using the [... setPositive:] REQUIRES a "+" before the number, it's not an option, so that doesn't work.
Gavin Eadie
@Gavin: Oh bugger, sorry about that. Although it is just as easy to strip the "+" sign, so wallyk's answer is the way to go.
dreamlax