Originally posted by 3R1C:
How does one round a float to say 2 decimal places? For instance:
1234.234535443238822
needs to be:
1234.23
at this point id be happy if i could just lop off everything after 2 decimals.
is it for display only or will you need to use the rounded number for more calculations?
outputing a rounded float could be done with printf("%.2f", your_float); or with a NSNumber Formatter. to keep it a number you could try multiplying by 100, adding 0.5, grab the int value, and then divide by 100.
just an idea, there may be a much simpler way i am unaware of, ( a round(f, 2) function might exist or you might be able to use sprintf and the %.2f control string to get a string version of your float and then cast it to a float via a strtod call.
hope this helps,
kido