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]
精彩评论