开发者

NSString not loading double value

I'm not sure what's going on here. For some reason NSString seems unwilling to load in the double value d.

Here's my code:

-(NSString*)minuteFormat:(double) d{
    NSString* mystring;
    if(d >= 10){
        mystring = [NSString stringWithFormat:@"%d", d];
    }else{
        mystring = [NSString stringWithFormat:@"0%d",d];
    }
    return(mystring);


}

Regardless of the value of d, the only thing that's getting returned is 0 or 00. (And I'm sure d is getting inputted correctly, as I'v开发者_如何学JAVAe used breakpoints to check.)

Could someone tell me what's going on?


%d is for integers. You probably want %f. See String Format Specifiers


%d is a decimal integer format string. Try %lf for double.


You should use %f (double) like this

mystring = [NSString stringWithFormat:@"%f", f];

or do a typecast of the value. For this you may use [yourString floatValue]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜