Monday, May 13, 2013

NSString doubleValue example ios


Returns the floating-point value of the receiver’s text as a double.
- (double)doubleValue
Return Value of [NSString doubleValue]
The floating-point value of the receiver’s text as a double. Returns HUGE_VAL or –HUGE_VAL on overflow, 0.0 on underflow. Returns 0.0 if the receiver doesn’t begin with a valid text representation of a floating-point number.
Discussion of [NSString doubleValue]
This method skips any whitespace at the beginning of the string. This method uses formatting information stored in the non-localized value; use an NSScanner object for localized scanning of numeric values from a string.
Example of [NSString doubleValue]
static bool TextIsValidValue( NSString* newText, double &value )
    bool result = false;

    if ( [newText isMatchedByRegex:@"^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"] ) {
     result = true;
     value = [newText doubleValue];
    return result;
Example of [NSString doubleValue]
NSString *test = @"22.414";
NSLog(@"doubleValue: %f", [test doubleValue]);
Example of [NSString doubleValue]
NSString *value = [valuelist objectAtIndex:valuerow];
NSString *value2 = [valuelist2 objectAtIndex:valuerow2];
double cal = [value doubleValue] + ([value2 doubleValue] * 8) + 3;
NSString *message =[[NSString alloc] initWithFormat:@"%f",cal];