• 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: [newbie] numeric strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] numeric strings


  • Subject: Re: [newbie] numeric strings
  • From: Marco Scheurer <email@hidden>
  • Date: Thu, 17 Jun 2004 14:49:22 +0200

On Jun 16, 2004, at 8:47 PM, Dustin Voss wrote:

On 16 Jun, 2004, at 7:14 AM, Randall Meadows wrote:

At 1:40 PM +0200 6/16/04, Robert Kuilman wrote:

Well,

the NSString class has the
- intValue
- floatValue
- doubleValue

selectors, which all return 0(.0) if the string not a valid {int,float,double} value.

Just out of curiousity, how does one distinguish between an "error" condition caused by the string "a1b2c3" and a valid input of "0", "0.0", or even "00000.000", all of which would return the value of 0 or 0.0 (depending on the selector)?

This, of course, is the problem with return values in C-based languagues. There's no way to tell. In Java, they'd toss an exception, Carbon would have used an "out" parameter, Dylan would return false instead of an integer (they are different), and if Cocoa was more self-consistent, it would return nil instead of an NSNumber.

Maybe raise an exception, because I fail to see how int, float, doubleValue could return nil.

- (void) test_decimalNumberWithString
{
should ([[NSDecimalNumber decimalNumberWithString:@"one"] isEqual:[NSDecimalNumber notANumber]]);
shouldnt ([[NSDecimalNumber decimalNumberWithString:@"1"] isEqual:[NSDecimalNumber notANumber]]);
}

Test Case '-[TestDelay test_decimalNumberWithString]' passed (0.002 seconds).


Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: [newbie] numeric strings (From: Randall Meadows <email@hidden>)
 >Re: [newbie] numeric strings (From: Dustin Voss <email@hidden>)

  • Prev by Date: Re: Detail view beginner question
  • Next by Date: Re: Scrolling List of Thumbnails?
  • Previous by thread: Re: [newbie] numeric strings
  • Next by thread: Defining a constant as private
  • Index(es):
    • Date
    • Thread