Amir - 7 months ago 34

Objective-C Question

I have double number in a format like

`34.123456789`

I just want 3 digits after the decimal point.

Answer

You can print it to 3 decimal places with `[NSString stringWithFormat:@"%.3f",d]`

.

You can approximately round it with `round(d*1000)/1000`

, but of course this isn't guaranteed to be exact since 1000 isn't a power of 2.