Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scanfloat & Locale



I'm trying to scan a list of floats from an http page.

The float numbers use:
- "." as 1000 separator
- "," as decimal separator

I've set the locale for the Scanner to correctly recognize the separators, but it does not work.
The Scanner seems to completely ignore the locale settings.


Here below a simplified version of my code and the correspondent Run Log

What's wrong with my code?


Thanks

Marco


- (IBAction)test:(id)sender
{
NSScanner *theScanner;
NSString *scanString = @"+2.000,56";
float floatValue;
NSMutableDictionary *scannerLocale = [NSMutableDictionary dictionaryWithCapacity:2];
// Create the Scanner
theScanner = [NSScanner scannerWithString:scanString];
// Set the CharactersToBeSkipped
[theScanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"+"]];
// Set the locale for the Scanner
[scannerLocale setObject:@"." forKey:NSLocaleGroupingSeparator];
[scannerLocale setObject:@"," forKey:NSLocaleDecimalSeparator];
[theScanner setLocale:scannerLocale];
NSLog(@"Locale Grouping Separator: %@", [[theScanner locale] objectForKey:NSLocaleGroupingSeparator]);
NSLog(@"Locale Decimal Separator: %@", [[theScanner locale] objectForKey:NSLocaleDecimalSeparator]);
// Scan the string
if ([theScanner scanFloat:&floatValue]) {
// Add values to the stocksListValues dictionary
NSLog(@"floatValue:%f", floatValue);
} else {
NSLog(@"Scan Error");
}
}


[Session started at 2005-07-30 17:24:39 +0300.]
2005-07-30 17:24:40.386 Test[2252] init <Test: 0x34b550>
2005-07-30 17:24:42.539 Test[2252] Locale Grouping Separator: .
2005-07-30 17:24:42.539 Test[2252] Locale Decimal Separator: ,
2005-07-30 17:24:42.540 Test[2252] floatValue:2.000000


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.