Is there some way I can get the value of the non integral portion of a double
(title cont.: 'double into an integer')
Because the modulus (%) operator doesnt want to work with doubles or floats.
[edited by - unliterate on May 30, 2004 9:48:45 PM]
You didn''t specify which language, but here''s how you could do it
Double someNumber, nonIntegralPart
Long x
x = get the integral part of someNumber
nonIntegralPart = someNumber-x
Double someNumber, nonIntegralPart
Long x
x = get the integral part of someNumber
nonIntegralPart = someNumber-x
Sry, c++, and i need the value isolated into an int. not a double. all ive come up with is
this isnt working how i need it to for some reason, does using int() as i do up there permanently change the value of number or is it just modified for the comparison?
[edited by - unliterate on May 30, 2004 10:07:54 PM]
while(int(Number+.99999999999)>int(Number)) { Number*=10; }
this isnt working how i need it to for some reason, does using int() as i do up there permanently change the value of number or is it just modified for the comparison?
[edited by - unliterate on May 30, 2004 10:07:54 PM]
Well i just debugged and that portion of my code works as it should, so the problem must lie else where.
EDIT: after more debugging i relised there is a problem. it seems very inconsistant, sometimes this produces the desired result and sometimes it doesnt for diferent values of Number. (sometimes the output will looke like 1.2e^16 for Number=1.2;
[edited by - unliterate on May 30, 2004 10:16:32 PM]
[edited by - unliterate on May 30, 2004 10:17:56 PM]
EDIT: after more debugging i relised there is a problem. it seems very inconsistant, sometimes this produces the desired result and sometimes it doesnt for diferent values of Number. (sometimes the output will looke like 1.2e^16 for Number=1.2;
//testint main(){ double Number=233.1234; while(long(Number+.99999)>long(Number)) { Number*=10; } cout<<Number; cin>>Number; return 0;}
[edited by - unliterate on May 30, 2004 10:16:32 PM]
[edited by - unliterate on May 30, 2004 10:17:56 PM]
Sort of off the top of my head, but you could convert the number into a string, shorten the string to consist only of the "non-integral part", then convert that string back to an integer. This is probably the least-efficient method
Sorry we don''t know what you are talking about.
You say you need the nonintegral portion of a double to be "isolated into" an int. That doesn''t even make sense.
You say you need the nonintegral portion of a double to be "isolated into" an int. That doesn''t even make sense.
quote:Original post by 3DNeophyte
Sort of off the top of my head, but you could convert the number into a string, shorten the string to consist only of the "non-integral part", then convert that string back to an integer. This is probably the least-efficient method
If you ABSOLUTELY NEED to do something like this, I''d probably go with this. It might not be the fastest way but at least its clean in its own sort of perverted way
'Sorry we don't know what you are talking about.
You say you need the nonintegral portion of a double to be "isolated into" an int. That doesn't even make sense.
'
it sure makes sence to me.. the problem is its not consistant with any code im showing so ill redescribe what i need.
given
double 12.34
i want
int 1234
[edited by - unliterate on May 30, 2004 10:21:11 PM]
You say you need the nonintegral portion of a double to be "isolated into" an int. That doesn't even make sense.
'
it sure makes sence to me.. the problem is its not consistant with any code im showing so ill redescribe what i need.
given
double 12.34
i want
int 1234
[edited by - unliterate on May 30, 2004 10:21:11 PM]
Still don''t quite get it. Suppose you have:
double d = 1.0 / 3.0;
what would you like the answer to be for d?
double d = 1.0 / 3.0;
what would you like the answer to be for d?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement