• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNumberFormatterPercentStyle flakiness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumberFormatterPercentStyle flakiness


  • Subject: Re: NSNumberFormatterPercentStyle flakiness
  • From: Deborah Goldsmith <email@hidden>
  • Date: Thu, 19 Jun 2008 15:05:59 -0700

Please write a bug.

Thanks,

Deborah Goldsmith
Apple Inc.
email@hidden

On Jun 15, 2008, at 5:22 AM, Aron Nopanen wrote:

Hi,

I've noticed some odd behavior with NSNumberFormatterPercentStyle in NSNumberFormatter (on Leopard 10.5.3). Attempting to translate an invalid string to a number causes subsequent number-to-string conversions to give invalid results. 'Invalid results' can be more accurately defined as 'correct value * 100'.

The following brief example illustrates. First, I create a number formatter with 'percent' style. It translates '0.01' to string "1%". I then try to translate an invalid string ("blah"; anything will do) to a number. Finally, I again translate '0.01' to a string, and get "100%" instead.

I've tried setting the multiplier to '1', which gives the same results with the decimal point shifted two places to the left. I verified in the debugger that the formatter attributes don't change during program execution.

Localization is English, New Zealand. English, United States gives the same results.

Source and output follow.  Any ideas?

Regards,
Aron

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSNumberFormatter *nf;
	nf = [[NSNumberFormatter alloc] init];

	[nf setNumberStyle:NSNumberFormatterPercentStyle];

	// Get string value for 0.01; results in 1%
	NSNumber *num = [NSNumber numberWithFloat:0.01];
	NSLog(@"\"%@\" gives \"%@\"", num, [nf stringFromNumber:num]);

	// Attempt to translate any invalid string
	NSString *str = @"blah", *err;
	id obj = nil;
	[nf getObjectValue:&obj forString:str errorDescription:&err];
	NSLog(@"String \"%@\" gives \"%@\" error \"%@\"", str, obj, err);

	// Get string value for 0.01, again; results in 100%
	NSLog(@"\"%@\" gives \"%@\"", num, [nf stringFromNumber:num]);

	[nf release];
	[pool drain];
	return 0;
}

Output:

2008-06-16 00:13:20.094 NumberFormatterPlay[13343:10b] "0.01" gives "1%"
2008-06-16 00:13:20.108 NumberFormatterPlay[13343:10b] String "blah" gives "(null)" error "Formatting error."
2008-06-16 00:13:20.108 NumberFormatterPlay[13343:10b] "0.01" gives "100%"


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSNumberFormatterPercentStyle flakiness (From: Aron Nopanen <email@hidden>)

  • Prev by Date: Re: install_name_tool
  • Next by Date: Help debugging why NSOutlineView stops updating
  • Previous by thread: NSNumberFormatterPercentStyle flakiness
  • Next by thread: Custom NSMenu
  • Index(es):
    • Date
    • Thread