Using only the decimal and leaving out the whole number

Pages: 12
How to I leave out the whole number in a number and only use the decimal?
I will use 52546.1351351 as a example instead of 52546.1351351, I want 0.1351351
I know how display all of this... using the function setprecision()
Take its modulus when divided by one.
mysteryfloat -= (mysteryfloat % 1) That will divide out the entire whole section and leave only the decimal remainder.
Thank you, you have been a big help lately also
so if i had a previous variable i was using
i would write the line like this
nextvar = prevar -= (prevar % 1)

Last edited on
Ugh. Conversion to integer and conversion back to float? Seriously?

http://www.cplusplus.com/reference/clibrary/cmath/modf/
Then change it to
mysteryfloat -= (mysteryfloat % 1.0);
Isn't that the same?
so my code is




1
2
3
4
5
6
7
8
9
10
JDN_I = (1461 * (Y_I + 4800 + (M_I - 14)/12))/4 +(367 * (M_I - 2 - 12 * ((M_I - 14)/12)))/12 - (3 * ((Y_I + 4900 + (M_I - 14)/12)/100))/4 + D_I - 32075; // julian day number algorithm
AJDN_I = JDN_I - 1;
TOD_I = (H_I * 3600) + (MN_I * 60) + S_I;
SEC_I = TOD_I/86400;
OUT_I = AJDN_I + SEC_I;

// Algorithms for processing elapsed time

PROC = OUT - OUT_I;
MOD = PROC -= (PROC %1.0)


is that it???
Last edited on
Or you can go for helios's recommendation of modf, which is modulus for floats. Check his link for its usage. I personally don't think the code overhead is worth the worry in most cases but hey, who knows?
WAIT - you should not have that mod = part. That shold not really be done. You are cramming too many statements together and the flow is difficult to read. In addition you missed your semicolon.
Do your assignment on another line. Even if it doesn't lead to a syntax error it looks better and is much clearer.
Last edited on
it is part of finding the number im trying to find i have to do it
and i was using a double
tummychow: That's at least as bad, if not worse. Modulo can't be performed on floating point values (there's a math function that does that), so its operands have to be converted to integers. If the compiler is not automatically converting 1.0 to 1, then it's worse.

EDIT:
modf, which is modulus for floats.
What? No it isn't.
Last edited on
Alright, fair enough.
WAIT - you should not have that mod = part. That shold not really be done. You are cramming too many statements together and the flow is difficult to read. In addition you missed your semicolon.
It looks fine to me.
okay but all those letters are variables that need to be used or i would be doing this on one line and to me i can read it perfectly...
so is line 10 how i do it?
Ugh. Conversion to integer and conversion back to float? Seriously?

Helios, Then how do i do it. I am not using floats. I am using doubles...
Floats and doubles are practically interchangeable. Double is just *longer* than float.
Read the link that helios gave you. We don't give people links so they can read the address. It's so they can read what's on the other end of the link.
Oh sorry I didn't see that.
i still dont know how this:
1
2
3
4
5
6
7
8
9
10
11
/* modf example */
#include <stdio.h>
#include <math.h>
{
  double param, fractpart, intpart;

  param = 3.14159265;
  fractpart = modf (param , &intpart);
  printf ("%lf = %lf + %lf \n", param, intpart, fractpart);
  return 0;
}




can turn into making a whole number with a decimal just a decimal....
im a semi intelligent guy that doesnt understand crap about math (pardon my language)

im making a semi intelligent guess and saying i wont need printf and all i may double param, fractpart, intpart; and fractpart = modf (param , &intpart);
and need to make param a variable?????
This seems really coplicated
i dont know ill look at that link a little more then google it then ask for more help

Last edited on
1
2
double x,
	fractional=modf(1.23,&x);

That's complicated?
1
2
3
4
5
6
//yep....how about....
double n = 523672.76345;
    double m = 523672.0;
    double rem;
    rem=n-m;
    cout<<"remainder: 0."<<rem;//prints remainder: 0.76345 

Last edited on
Okay, so how do you obtain m for any value of n?
1
2
double x,
fractional=modf(1.23,&x);


That's complicated?

Uh, Yeah I guess it is complicated
Last edited on
Pages: 12