• 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
Scanfloat & Locale
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scanfloat & Locale


  • Subject: Scanfloat & Locale
  • From: Marco Michieli <email@hidden>
  • Date: Sat, 30 Jul 2005 17:56:04 +0300

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: This email sent to email@hidden
  • Prev by Date: Re: Newbie: Getting an NSWindow and setting its delegate
  • Next by Date: Re: Path of USB drive on Mac????
  • Previous by thread: Re: Newbie: Getting an NSWindow and setting its delegate
  • Next by thread: longjmp exit
  • Index(es):
    • Date
    • Thread