Public Group

#### 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 5309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
You didn''t specify which language, but here''s how you could do it

Long x

x = get the integral part of someNumber

##### 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 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;

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

##### 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 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 on other sites
Could i do that with an array of chars? ive never used those std::string things or w/e

##### 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 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 on other sites
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?

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013393
×