Q:

Removing characters after the decimal point for a double

How can I remove the all the characters after the decimal point.
Instead of 7.3456, I would just like 7.
This is what I do to get the number so far with decimal places.
[NSString stringWithFormat:@" %f : %f",(audioPlayer.currentTime),(audioPlayer.duration) ];

Many Thanks,
-Code

A:

You can specify what you want using format string :  
[NSString stringWithFormat:@" %.0f : %.0f", (audioPlayer.currentTime),
                                            (audioPlayer.duration)];

A:

If you want this for display, use an NSNumberFormatter:
double sevenpointthreefourfivesix = 7.3456;
NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:0];
NSLog(@"%@", [formatter stringFromNumber:[NSNumber numberWithDouble:sevenpointthreefourfivesix]]);

2011-12-20 20:19:48.813 NoDecimal[55110:903] 7

If you want a value without the fractional part, use round(). If you want the closest integer value not greater than the original value, use floor().

A:

floorf() is the function you're looking for.

