You can use the class NSScanner to find out if you got a valid double
with this method :
- (BOOL)scanDouble:(double *)doubleValue
once you have initialized your scanner with your string.
Why (double *)
?
Because you want the method to return to you 2 informations, the doubleValue
and is it a valid double
. The latter is given by the BOOL and for the former only a Pointer can get you a value out of a method call (apart from the return value)
Parameters
doubleValue
Upon return, contains the scanned value. Contains HUGE_VAL or –HUGE_VAL on overflow, or 0.0 on underflow.
Return Value
YES if the receiver finds a valid floating-point representation, otherwise NO.