conversion to doubleValue doesn’t work .. but to integerValue does

Discussion in 'iOS Programming' started by ulquiorra, Sep 25, 2009.

  1. ulquiorra macrumors member

    Jun 17, 2009
    Hello all I'm trying to convert a string to a double and it doesn't work. However if I convert it to an integer it does work

    this is my code snippet
    int myDuration = [myDurationString integerValue];
    int conversionMinute = myDuration / 60;
                            if( myDuration < 60 )
                                    [appDelegate.rep1 addObject:[NSString stringWithFormat:@"%d",myDuration]];
                                    NSLog(@"show numbers %d", myDuration);
                                    [appDelegate.rep1 addObject:[NSString stringWithFormat:@"%d",conversionMinute]];
                                    NSLog(@"show numbers %d", conversionMinute);
    Now if I try to do

    double myDuration = [myDurationString doubleValue];
    double conversionMinute = myDuration / 60;
    then it doesn't work. It gives me an output of 0.

    So the integerconversion works but somehow the double doesn't does anybody have an idea why?

    ps. I already tried changing the format specifier to %f ... still no succes.
  2. jnic macrumors 6502a

    Oct 24, 2008
    double conversionMinute = myDuration / 60[COLOR="Red"].0[/COLOR];
    Otherwise, you're dividing by an integer, which will cause a cast and be floored, resulting in a zero output in this case.
  3. ulquiorra thread starter macrumors member

    Jun 17, 2009
    thanks for your reply , the problem though has already been solved.

    It did some other stuff a elsewhere in my code that kind of messed it up a little thanks though ;)

Share This Page