nsnumberformatter

Is it a good idea to prefer NSNumberFormatterBehavior10_4 over NSNumberFormatterBehaviorDefault?

I wonder if it would be more secure to rely on a NSNumberFormatterBehavior10_4 instead of default, because default may change arbitrary some day in future, and suddenly the app looks ugly. Or am I wrong with that? ...

Format Integer as Two Places Decimal

I am presenting the user with a field that displays the number keyboard and only want them to be able to enter numbers--no decimals. Since the field is a currency field, however, I want the number to always display with two decimal places. You've probably seen this type of an interface at an ATM. I've looked at the NSNumberFormatter doc...

how do I round numbers with NSNumberFormatter

I've got a calculation for example 57 / 30 so the solution will be 1,766666667.. How do i first of all get the 1,766666667 i only get 1 or 1.00 and then how do i round the solution (to be 2)? thanks a lot! ...

Displaying of fractional values using a NSNumberFormatter?

My requirement is to display fractional values if the user wants to enter the fractional values in the text fields. I haver a textfield where i should display the values entered seperated with commas and also it should allow to enter only 9 integer digits and 2 digits after decimal point(Fractional Values). I have tried using the NSNumbe...

How to display currency without rounding as string in Xcode?

Hello everyone, I have trouble when I have currency value 999999999999999999.99 From that value, I want to display it as String. The problem is that value always rounded to 1000000000000000000.00 I'm not expect that value rounded. I want the original value displayed. Do you have any idea how to solve this problem? I tried this code f...

Using NSNumberFormatter to pad spaces between a currency symbol and the value

Hi Apologies if this is a dumb question but I'm trying to format a currency value for my iphone app and am struggling to left-justify the currency symbol, but right-justify the value. So, "$123.45" is formatted as (say) $ 123.45 depending on format-width. This is a kind of accounting format (I think). I've tried various methods with...

Re-Apply currency formatting to a UITextField on a change event

Howdy all, I'm working with a UITextField that holds a localized currency value. I've seen lots of posts on how to work with this, but my question is: how do I re-apply currency formatting to the UITextField after every key press? I know that I can set up and use a currency formatter with: NSNumberFormatter *currencyFormatter = [[NSN...

How do I set an Integer in a UITextfield using Core Data?

I can set text in my managed object like this... [editedObject setValue:textField.text forKey:editedFieldKey]; but I can't set this... [editedObject setValue:numberField.text forKey:editedFieldKey]; In the XCode Template I can set this straight into the Managed Object but like this... setValue:[NSNumber numberWithInt:200] forKey:@...

NSNumberFormatter weirdness with NSNumberFormatterPercentStyle

Hi, I need to parse some text in a UITextField and turn it into a percentage. Ideally, I'd like the user to either type something like 12 or 12% into the text field and have that be parsed into a number as a percentage. Here's what's weird. The number formatter seems to not like 12 and seems to divide 12% by 10000 instead of 100: NSN...

NSNumberFormatter crashing iPhone SDK 4.0b2

Hey there, I've got an app that's been in the app store for a while and functions perfectly on OS 3.1 - 3.13. However, when tested on 4.0b2 I noticed that it crashes in the same place every time, but only on the device, never on the simulator. I'm using a 3GS to test. On loadView I initialize an NSNumberFormatter object which is decl...

More specific NSNumberFormatter failure behaviour

I have an NSTextField into which I need the user to enter a number between a max and min, and it would be nice if I could detect when the NSNumberFormatter fails that particular test so I can either display a nicer message ("The number is too large" is not very helpful, it needs to display the valid range) or simply set the field automat...

NSString - max 1 decimal of a float

Hi everyone, I would like to use a float in a NSString. I used the stringWithFormat and a %f to integrate my float into the NSString. The problem is that I would like to display only one decimal (%.1f) but when there is no decimals I don't want to display a '.0' . How can I do that? Thanks ...

Working with NSNumberFormatter

I have a question that I am looking for the answer to. I am not really understanding NSNumberFormatter. I've stared at the documentation for a while, and can't seem to understand why I can't get setMinimum (or setMaximum) to work at all. Here is the code I am using: NSNumberFormatter* numberFormatter = [[[NSNumberFormatter alloc] ini...

Formatting the number entered in textfield in iPhone

I have a text field where the user enters a number, which is in the range of thousands. I want the text field to be formatted as the user enters the number, example : 200000 should become 200,000. how do i go about doing this?? Many Thanks, S ...

NSNumberFormatter not honoring digit information in scientific style

I am trying to display some decimals in a scientific style. I'm using NSDecimalNumber and NSNumberFormatter objects. When setting the minimum and maximum number of digits though, some information from the original number seems to be lost. For example, consider the following code example: NSDecimalNumber *dn = [NSDecimalNumber decimal...

NSNumberFormatter working Weird in iPhone 4.0

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 seper...

Efficient use of NSNumberFormatter related to NSString Categories

Hi All, I'm writing an NSString category that requires an NSNumberFormatter. I'm stuck between initing and releasing one every time my category is used to print a string in a certain way or initing the formatter in my app and passing it through. The NSNumberFormatter has a couple of config calls run on it first to make it work just ri...

NSNumberFormatter and 'th' 'st' 'nd' 'rd' (ordinal) number endings

Is there a way to use NSNumberFormatter to get the 'th' 'st' 'nd' 'rd' number endings? EDIT: Looks like it does not exist. Here's what I'm using. +(NSString*)ordinalNumberFormat:(NSInteger)num{ NSString *ending; int ones = num % 10; int tens = floor(num / 10); tens = tens % 10; if(tens == 1){ ending = @"th...

Formatting number as percentage

I don't understand how NSNumberFormatterPercentStyle works! Example: NSNumber *number = [NSNumber numberWithFloat:90.5]; NSNumberFormatter *percentageFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [percentageFormatter setNumberStyle:NSNumberFormatterPercentStyle]; NSString *strNumber = [percentageFormatter stringFromNumbe...

NSNumberFormatter removes trailing zeros

I have used NSNUmberFormatter in a cell of NSTableView. This NSNUmberFormatter is dragged from the IB library and put in the table view cell. Then from the inspector constraints are modified. However during run of the aplication when I enter some values which has trailing zeros e.g. 9.100, the cell displays only 9.1. How do I retain the ...