• 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: NSDecimalSeparator localization II
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDecimalSeparator localization II


  • Subject: Re: NSDecimalSeparator localization II
  • From: mark <email@hidden>
  • Date: Thu, 30 Dec 2004 17:20:06 -0800

I came up with a similar solution, but different:

I prepend the string (Note that I just add "1" in the format itself)
NSString*    theString = [NSString stringWithFormat:@"1%0.4lf", aValue];

theString = [theString stringByTrimmingCharactersInSet:...

// Where we differ is that I now use substringWithRange:
short len = [theString length];
theString = [theString substringWithRange:NSMakeRange(1, len-1)];

// I then apply the removal of the decimal separator
return [theString stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:(NSString *)[[NSUserDefaults
standardUserDefaults] objectForKey:NSDecimalSeparator]]];

Does anyone know which one might be better--i.e., is substringWithRange (+
the length call) costlier than stringByTrimmingCharactersInSet or is it the
other way around?

Thanks!

Mark
> From: Ricky Sharp <email@hidden>
> After thinking about this a bit more, you could still use
> stringByTrimmingCharactersInSet, but first modify your string such that
> it won't trim from the left.  For example, prefix it with say 'A'.
> After your trimming, remove that 'A'.
>
> - (NSString*)stringWithFormattedFloat:(float)aValue
> {
> NSString*    theString = [NSString stringWithFormat:@"%0.4lf", aValue];
>
> theString = [NSString stringWithFormat:@"A%@", theString];
>
> theString = [theString stringByTrimmingCharactersInSet:
> [NSCharacterSet characterSetWithCharactersInString:@"0."]];
>
> theString = [theString stringByTrimmingCharactersInSet:
> [NSCharacterSet characterSetWithCharactersInString:@"A"]];
>
> return theString;
> }
>
> This appears to work.  Note that "0" will become the empty string, but
> you mentioned that you already handle that special case.  And of course
> replace the hard-coded values with proper decimal separator.
>
> ___________________________________________________________
> Ricky A. Sharp         mailto:email@hidden
> Instant Interactive(tm)   http://www.instantinteractive.com
>

 _______________________________________________
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

References: 
 >Re: NSDecimalSeparator localization II (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Embedding a custom view within NSScrollView
  • Next by Date: Re: How to add a URL-tile to the Dock from an Installer?
  • Previous by thread: Re: NSDecimalSeparator localization II
  • Next by thread: multiple declarations for method `length' ?
  • Index(es):
    • Date
    • Thread