views:

29

answers:

2

I've not got the device price format setting.

NSNumber *temp = [NSNumber numberWithDouble:dblPrice];
NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithDecimal:[temp decimalValue]];

NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

return [currencyFormatter stringFromNumber:someAmount];

How do I get the short date setting ?

A: 

Not sure if I got you right, but if you want to format NSDate, you should use NSDateFormatter:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, YYYY"];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale:usLocale];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
[usLocale release];
[formatter release];
kovpas
-1 the answer is only good if the user is an American. Use `-setDateStyle:`
JeremyP
@JeremyP: you kidding me? Isn't it obvious, that if you want to use other date language, you should explicitly set it in initWithLocaleIdentifier: or remove whole locale trick if you want to use default?
kovpas
@kovpass: No, I'm not kidding you. The short date format is set by the *user* in the iphone settings app. You should not be overriding that with your `MMM d, YYYY` format string for any date that will be presented to the user.
JeremyP
+1  A: 
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
fluchtpunkt