[C] Extract integer and decimal part
Solved
Florent
-
dEpHI -
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 :)
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 :)
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...