NSNumberFormatter setExponentSymbol doing nothing (was Re: API to convert string to number?)
NSNumberFormatter setExponentSymbol doing nothing (was Re: API to convert string to number?)
- Subject: NSNumberFormatter setExponentSymbol doing nothing (was Re: API to convert string to number?)
- From: "E. Wing" <email@hidden>
- Date: Wed, 28 Feb 2007 14:46:04 -0800
So I'm still having problem with the exponent symbols. Calling
NSNumberFormatter's setExponentSymbol method seems to do nothing.
Calling exponentSymbol after the set yields a NULL value implying the
set didn't do anything. It also hasn't improved my situation about
converting a string with an exponent to a number. From the
documentation, I can't tell what exactly this method is supposed to do
for me so I don't know if this is going to actually help my original
problem. But at the very least, something seems wrong here with the
setter/getter.
Does this look like an Apple bug to anybody else. Below is a toy test
program. I'm on 10.4.8 and not using any backwards compatibility SDKs.
Thanks,
Eric
#import <Foundation/Foundation.h>
int main(int argc, char* argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
float converted_value;
NSNumberFormatter* number_formatter = [[[NSNumberFormatter alloc]
init] autorelease];
NSLog(@"exponentSymbol (before): %@", [number_formatter exponentSymbol]);
[number_formatter setExponentSymbol:@"e"];
NSLog(@"exponentSymbol (after): %@", [number_formatter exponentSymbol]);
NSLog(@"groupingSeparator: %@", [number_formatter groupingSeparator]);
NSLog(@"groupingSize: %d", [number_formatter groupingSize]);
// NSString* my_string = @"1,000";
NSString* my_string = @"1e3";
NSNumber* ns_number = [number_formatter numberFromString:my_string];
if(nil == ns_number)
{
NSLog(@"numberFromString failed");
[pool release];
return 0;
}
converted_value = [ns_number floatValue];
NSLog(@"converted_value is: %f", converted_value);
[pool release];
return 0;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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