[C] Extract integer and decimal part

Solved
Florent -  
 dEpHI -
Hello!

I have a problem in C: I'm trying to write a program, and at one point I need to retrieve the integer part and the decimal part of a number into two different variables.

For example, if I have a number 4.1256, I would like to obtain:
var1 = 4
var2 = 1256

In PHP, there are functions for this, but in C I haven't found anything :S So I'm turning to you, hoping that someone can give me a hand!

Have a good evening, thanks in advance :)

6 réponses

cfrezz
 
#include <math.h>

float a = 1.5;
// integer part
int o = floor(a);
// fractional part
float u = a-o;

there you go
100
dEpHI
 

response for cfrezz (and the others):

it only works for numbers less than the maximum value of a long

(4,294,967,295)

I made an algorithm, a little more complicated...

0