Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ulquiorra

macrumors member
Original poster
Jun 17, 2009
38
0
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
Code:
int myDuration = [myDurationString integerValue];
int conversionMinute = myDuration / 60;

                        if( myDuration < 60 )
                        {
                                [appDelegate.rep1 addObject:[NSString stringWithFormat:@"%d",myDuration]];
                                NSLog(@"show numbers %d", myDuration);
                        }
                        else
                        {
                                [appDelegate.rep1 addObject:[NSString stringWithFormat:@"%d",conversionMinute]];
                                NSLog(@"show numbers %d", conversionMinute);
                        }

Now if I try to do

Code:
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.
 
Code:
double conversionMinute = myDuration / 60;

then it doesn't work. It gives me an output of 0.

Try:
Code:
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.
 
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 ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.