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

need help about printing a decimal number

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



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

need help about printing a decimal number
PostPosted: Tue Mar 21, 2006 4:22 am     Reply with quote

I need help with this kind of printf

I have this result : " 1234 "
I need to printf : " 12.34 "

Anyone can help me with some code to explain this ??

THANK YOU ALL !!
Ttelmah
Guest







PostPosted: Tue Mar 21, 2006 4:59 am     Reply with quote

I don't know what is gong on. I saw exactly this post 'yesterday', and replied to it. A number of other threads, seem to have disappeared. Hs there been a server crash or something?...

Anyway, the 'answer' depends on what compiler version you have. With the more recent compilers, the %w format will do what you want. On all but the very latest compilers, this is documented in the 'readme.txt' file in the compiler directory, rather than in the help file. So "%4.2w", will print a long integer, with two decimal places shown.
On older compilers, you have the choice of using float (lots of processor time), or printing the quotient, and remainder using two seperate outputs (using 'ldiv' to generate these is the most efficient way, if your compiler supports this).

Best Wishes
Calamar



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

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

PostPosted: Wed Mar 22, 2006 12:17 pm     Reply with quote

unsigned int16 number = 65123;
unsigned int16 numberInteger = number / 100;
unsgned int numberfraction = number % 100;

printf(lcd_putc,"%lu.%u", numberInteger,numberFaction);
_________________
Best Regards
Daniel H. Sagarra
La Plata (Argentina)
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