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

int variable to double

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

int variable to double
PostPosted: Sat Apr 12, 2008 11:40 am     Reply with quote

If i need to use a value to have a decimal value, how do i declare that variable?
I need to take an analog value of say 85 and divide it by 52.2. Then display that decimal value.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 12:00 pm     Reply with quote

See this sample program. It reads an unsigned integer from the A/D,
converts it to floating point, does some math on it, and displays the
floating point result:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sat Apr 12, 2008 12:08 pm     Reply with quote

Thanks. Got it working. I used the float declaration but in the printf of the lcd i never changed %u to %f.
That example program works well, thanks.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sat Apr 12, 2008 12:15 pm     Reply with quote

can you please explain this part of the program to me.

"\f%3.2f",

in the following line
printf(lcd_putc, "\f%3.2f", x1);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 12:29 pm     Reply with quote

You need to get a book on the C language, or use online tutorials.
For your question, you can do a search with http://www.google.com
for this:
Quote:
printf width precision

Here is one result. Look down at the bottom of this page to see how
the width and precision values affect the output.
http://irc.essex.ac.uk/www.iota-six.co.uk/c/c3_more_on_format_specifiers.asp

Also be aware that CCS doesn't always follow the full C standard
with regard to printf. In other words, there may be some differences
in the displayed result, compared to the Microsoft MSVC compiler.
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