• 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: getting rid of thousand separator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting rid of thousand separator


  • Subject: Re: getting rid of thousand separator
  • From: Tolga Katas <email@hidden>
  • Date: Fri, 19 May 2006 18:54:06 -0700

Thanks guys, that fixed it.

Here it is.
[[ myNumFmt numberFromString: inString ] intValue];




Pierce T. Wetter III wrote:


On May 19, 2006, at 5:44 PM, Shawn Erickson wrote:

On 5/19/06, Tolga Katas <email@hidden> wrote:

Hi List,

I have an NSString that holds a number like 14,500 ( with a comma ,
Thousands separator)
Is there an easy way to get rid of the separator so i can turn this into
an int?


-[NSString intValue] is one option to consider...

<http://developer.apple.com/documentation/Cocoa/Reference/ Foundation/ObjC_classic/Classes/NSString.html#//apple_ref/occ/instm/ NSString/intValue>


 That won't work.

 Testing it in python+pyobjc:

python

>> import objc
>> s = Foundation.NSString.stringWithString_("10,000")
>> print s.intValue()
10

What you want is an NSNumberFormatter:

>>> nf = Foundation.NSNumberFormatter.alloc().init()
>>> print nf.numberFromString_("10,000")
10000

Numberformatter can deal with other stuff too:

>>> print nf.numberFromString_("$10,000")
None
>>> nf.setFormat_("$##,##0.00")
>>> print nf.numberFromString_("$10,000")
10000


Pierce



--
Tolga Katas


_______________________________________________ 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: 
 >getting rid of thousand separator (From: Tolga Katas <email@hidden>)
 >Re: getting rid of thousand separator (From: "Shawn Erickson" <email@hidden>)
 >Re: getting rid of thousand separator (From: "Pierce T. Wetter III" <email@hidden>)

  • Prev by Date: Re: getting rid of thousand separator
  • Next by Date: IBPalette Custom Container view
  • Previous by thread: Re: getting rid of thousand separator
  • Next by thread: Bindings, CoreData, NSOutlineView, and NSTreeController
  • Index(es):
    • Date
    • Thread