Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Is there some way I can get the value of the non integral portion of a double

This topic is 5104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(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]

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sry, c++, and i need the value isolated into an int. not a double. all ive come up with is

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]

Share this post


Link to post
Share on other sites
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;


//test

int 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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
'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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!