• 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: Ricky Sharp <email@hidden>
  • Date: Thu, 30 Dec 2004 17:44:19 -0600


On Dec 30, 2004, at 5:32 PM, Ricky Sharp wrote:

Be careful when using stringByTrimmingCharactersInSet as it will trim from _both_ ends of the receiver.

The string 0.0050 will become 005

While I don't have time to do exhaustive testing, doing a "round-trip" conversion seems to do what you want:


- (NSString*)stringWithFormattedFloat:(float)aValue
{
	NSString*	theString = [NSString stringWithFormat:@"%0.4f", aValue];

	NSLog (@"intermediate string %@", theString);

	return [NSString stringWithFormat:@"%g", [theString floatValue]];
}

- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
	NSLog (@"final string %@", [self stringWithFormattedFloat:0]);
	NSLog (@"final string %@", [self stringWithFormattedFloat:0.987654]);
	NSLog (@"final string %@", [self stringWithFormattedFloat:0.5]);
}


Here's the test run output:

2004-12-30 17:43:30.862 trim[7854] intermediate string 0.0000
2004-12-30 17:43:30.863 trim[7854] final string 0
2004-12-30 17:43:30.863 trim[7854] intermediate string 0.9877
2004-12-30 17:43:30.863 trim[7854] final string 0.9877
2004-12-30 17:43:30.863 trim[7854] intermediate string 0.5000
2004-12-30 17:43:30.863 trim[7854] final string 0.5

___________________________________________________________
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


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

  • Prev by Date: Availability Macros, errors in cocoa headers?
  • Next by Date: Re: NSDecimalSeparator localization II
  • Previous by thread: Re: NSDecimalSeparator localization II
  • Next by thread: Re: NSDecimalSeparator localization II
  • Index(es):
    • Date
    • Thread