zeeshan ahmed
Joined: 02 Dec 2010 Posts: 22
|
Help needed regarding Floating numbers |
Posted: Tue Mar 22, 2011 6:59 am |
|
|
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 |
|