Get integer to decimal floating point (Objective-c)

I have a float like 23.248500. Is it possible for me to simply get the part 23and part 0.248500separately?

thank

+3
source share
3 answers

For positive numbers, you can use floor(f)to get 23and f - floor(f)to get a part 0.248500.

(I linked the link to C ++, but the same function is present in the C library).

+8
source

The right function for this modf().

+7
source

What about:

float f = 23.248500;
int a = (int)f;
float f_minus_a = f - a;
+5
source

All Articles