nsnumberformatter

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

China☆狼群 提交于 2019-11-27 12:39:20
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"; }else { switch (ones) { case 1: ending = @"st"; break; case 2: ending = @"nd"; break; case 3: ending = @"rd"; break; default: ending = @"th"; break; } } return [NSString stringWithFormat:@"%d%@", num, ending]; } Adapted from nickf's answer here Is there an easy way in .NET to get "st", "nd

How to get NSNumberFormatter currency style from ISOCurrencyCodes?

限于喜欢 提交于 2019-11-27 07:01:06
问题 If I were to have EUR, or USD (both ISO currency codes), how could I make my NSNumberFormatter to properly format me a string like this? For EUR code: 10.000,00 € For USD code: $10,000.00 I could do this by setting localeIdentifier. But I really need to get it from the ISO currency code. Is this possible? [numberFormatter stringFromNumber: [_property price]]; Thank you! 回答1: Use the setCurrencyCode: method of NSNumberFormatter . [numberFormatter setCurrencyCode:@"EUR"]; or [numberFormatter

Formatting a number to show commas and/or dollar sign

喜夏-厌秋 提交于 2019-11-27 05:03:18
I want to format my UILabel with commas or better with a dollar sign and commas (with no decimal). Here is the code I am using: IBOutlet UILabel *labelrev float rev = (x + y) labelrev.text = [[NSString alloc] initWithFormat:@%2.f",rev]; I get xxxxxxxxx as the output I want to get xxx,xxx,xxx or $xxx,xxx,xxx How do I do that? You should definitely use NSNumberFormatter for this. The basic steps are: Allocate, initialize and configure your number formatter. Use the formatter to return a formatted string from a number . (It takes an NSNumber, so you'll need to convert your double or whatever

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

馋奶兔 提交于 2019-11-26 22:35:29
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 = [[NSNumberFormatter alloc] init]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; ... [currencyFormatter stringFromNumber:...]; but I don't know how to hook it up. For instance, if the value in the field reads "$12,345" and the user taps the "6" key, then the

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

半腔热情 提交于 2019-11-26 16:07:53
问题 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"; }else { switch (ones) { case 1: ending = @"st"; break; case 2: ending = @"nd"; break; case 3: ending = @"rd"; break; default: ending = @"th"; break; } } return [NSString stringWithFormat:

Struggling with NSNumberFormatter in Swift for currency

五迷三道 提交于 2019-11-26 12:54:36
I am creating a budget app that allows the user to input their budget as well as transactions. I need to allow the user to enter both pence and pounds from separate text fields and they need to be formatted together with currency symbols. I have this working fine at the moment but would like to make it localised as currently it only works with GBP. I have been struggling to covert NSNumberFormatter examples from Objective C to Swift. My first issue is the fact that I need to set the placeholders for the input fields to be specific to the users location. Eg. Pounds and Pence, Dollars and Cents

Formatting a number to show commas and/or dollar sign

删除回忆录丶 提交于 2019-11-26 11:27:22
问题 I want to format my UILabel with commas or better with a dollar sign and commas (with no decimal). Here is the code I am using: IBOutlet UILabel *labelrev float rev = (x + y) labelrev.text = [[NSString alloc] initWithFormat:@%2.f\",rev]; I get xxxxxxxxx as the output I want to get xxx,xxx,xxx or $xxx,xxx,xxx How do I do that? 回答1: You should definitely use NSNumberFormatter for this. The basic steps are: Allocate, initialize and configure your number formatter. Use the formatter to return a

Struggling with NSNumberFormatter in Swift for currency

有些话、适合烂在心里 提交于 2019-11-26 03:08:38
问题 I am creating a budget app that allows the user to input their budget as well as transactions. I need to allow the user to enter both pence and pounds from separate text fields and they need to be formatted together with currency symbols. I have this working fine at the moment but would like to make it localised as currently it only works with GBP. I have been struggling to covert NSNumberFormatter examples from Objective C to Swift. My first issue is the fact that I need to set the