-
July 15th, 2013, 06:38 PM
#1
A question regarding float and double
Suppose we want to decide the position of point in a float or a double, here is what I do,
Code:
float d;
int count = 0;
while(d!=(int)d)
{
d *= 10;
count++;
}
Here count is the position of point. Suppose d = 3.1415, at the end of code, count = 7 and d = 31415002. Basically this is not what I want. I expect at the end, d = 31415 and count = 4. But it is even worse when d is a double. Iencounter an infinite loop. Why? And what is reliable way to do what I expect to do? Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|