Using only the decimal and leaving out the whole number

Pages: 12
Uh... I gave you the reference to modf(). How much more explanation do you need?
Last edited on
Uh... I gave you the reference to modf(). How much more explanation do you need?

i really dont know i just dont have any clue how to use modf even with the reference because the reference is specified in only 1 way in only 1 example.


I dont get how to drop the whole number and how to keep the decimal
i thought this was easy... apparently it is hard. ( for me )
Edit: If this is too much to ask for then forget it: but maybe an example program would help.
Last edited on
the reference is specified in only 1 way in only 1 example.


How many examples do you need?

Here's another one, even though it's pretty much exactly the same example as on the modf page:

1
2
3
4
5
double original_number = 123.456;
double decimal;
double whole;

decimal = modf(original_number,&whole);


'decimal' and 'whole' are now set as you'd expect. (decimal = 0.456, whole = 123)

EDIT:

Edit: If this is too much to ask for then forget it: but maybe an example program would help.


The modf page has an example program.
Last edited on
Sorry. I guess i was too lazy to look at the example.
Ok-- would someone scratch my thread above?
Of course the heleos solution using fmod is the shortest and easiest to implement and understand.
another way (I think it's quick 'n dirty (I'm a beginner too)):

1
2
3
  float x = 8.0, y = 7.0, z;
  z = x/y;
  z -= int(z); 


or:

 
    float z1 = (x/y) - int(x/y);


I'm interested in feedback about this "hacks"
better to use modf.

integers and floating points are stored in two entirely different fashions, so switching between one and the other (and back) as you are doing is a whole process. It's best to avoid that if you can.
Topic archived. No new replies allowed.
Pages: 12