• 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 14:07:36 -0800


> From: Sean McBride <email@hidden>
>> unsigned int len = [aString length];
>> if (len <= 2)    // can't have trailing zero's with a string length of 2
>> or less
>> return;
>
> What about a string like ".0"?  A degenerate example I know. :)
Actually, I have it covered somewhere else--I don't allow zero values.

>
>> if (!(c >= '1' && c <= '9'))
>
> Not all languages use the characters 0 to 9.  Happily, there is
> [NSCharacterSet decimalDigitCharacterSet] and NSString's
> stringByTrimmingCharactersInSet, which you can use together to do this
> more nicely.
>

> You can also use the above to check if NSDecimalSeparator has any numbers
> in it, then maybe just don't touch the string at all.
Well, that shows up a BIG hole in my localization knowledge.  I had thought
that the '0' decimal-type character set was universal.  Oh well.

So if I understand correctly (it works in my testing, but I wanted to make
sure), I should change things to:

if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember: '0'])
// if not '0' based, don't trim
    {
        aString = [*fromString
stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"0"]];  // strip trailing zero's

// Note: can't strip both 0's and decimal point at the same time because it
// will overstrip--turing 10000.00 into 1, while we want it 10000
aString = [aString stringByTrimmingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:(NSString *)[[NSUserDefaults
standardUserDefaults] objectForKey:NSDecimalSeparator]]];

// now strip trailing decimal point
        *fromString = aString;
     }

 _______________________________________________
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

  • Follow-Ups:
    • Re: NSDecimalSeparator localization II
      • From: Ricky Sharp <email@hidden>
    • Re: NSDecimalSeparator localization II
      • From: "Sean McBride" <email@hidden>
References: 
 >Re: NSDecimalSeparator localization II (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: Startup Items and usability
  • Next by Date: NSTextFieldCell: get number of wrapped lines?
  • Previous by thread: Re: NSDecimalSeparator localization II
  • Next by thread: Re: NSDecimalSeparator localization II
  • Index(es):
    • Date
    • Thread