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 support@ccsinfo.com

Help needed regarding Floating numbers

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



Joined: 02 Dec 2010
Posts: 22

View user's profile Send private message

Help needed regarding Floating numbers
PostPosted: Tue Mar 22, 2011 6:59 am     Reply with quote

Hi all ,
I'm new to ccs forum. I need some help regarding floating numbers. What I want to do is to break floating number e.g 998.76 into separate integers & then store in separate variables like i=9, j=9, k=8 etc.
I'm using 18f252 running at 20 MHz.
I use the following code ...but upto my knowledge this only works for 16 bit unsigned numbers. It is working fine with number less than 655.35 . What should I do to make it work for 32 bit numbers also?
Code:

ldiv_t ldivval;
float starting_val;

ldivval=ldiv((signed int16)(starting_val*100),10);
hundredth=ldivval.rem;
ldivval=ldiv(ldivval.quot,10);
tenth=ldivval.rem;
ldivval=ldiv(ldivval.quot,10);
ones=ldivval.rem;
ldivval=ldiv(ldivval.quot,10);
tens=ldivval.rem;
hunds=ldivval.quot;


I also use sprintf function to do the same ....but its taking too much time (arround 8ms at 20MHz) to execute, but working fine.

Please help....
Thanks
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