CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Float to integer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Float to integer
PostPosted: Wed Feb 02, 2005 5:42 am     Reply with quote

I have got a float variable of 32 bits,
I am trying to make a casting to integer:
integer_variable = (int) float_variable;
The float variable contains some data, but after the above command, the integer_variable remains zero.
How can I solve this?
Thank you
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Wed Feb 02, 2005 7:18 am     Reply with quote

Help us out here and tell us what the data is!! If it is between 1 and -1 (negative exponent), the result of the conversion should be 0. Also, what is the expected range of data that you will be trying to convert?
Ian McCrum



Joined: 26 Oct 2003
Posts: 14
Location: Northern Ireland

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 05, 2005 1:25 pm     Reply with quote

A really inefficient way to convert floats is to use sprintf to convert floats to an ascii string, you can then see what value you have and it may be a more convenient way to store things anyway. You can always use atoi() or atol() to convert the asciii to an int or long.

In your particular case, setup a number of test cases, it may be that casts are not doing what you want.

Cheers
_________________
Ian McCrum, email address held at
www.eej.ulst.ac.uk/~ian
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group