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

printf and float number

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



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

printf and float number
PostPosted: Thu Oct 07, 2010 1:56 am     Reply with quote

Hello
I want print my result on the GLCD but I want the formate to be fixed I mean:
Code:

printf(glcd_putc,"%04.3f",KN);

When kn=0 I want the result on the GLCD to be 0000.000
When kn=123.4 I want the result on the GLCD to be 0123.400

Any suggestions please ?


Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Thu Oct 07, 2010 2:45 am     Reply with quote

You need to understand one thing. The number in front of the point, on a printf format, is _not_ the digits in front of the decimal in the result. It is the _total output width_, so that it stays the same for all outputs). This is a common thing 'missed' by people who are used to other languages. So you need to to work out the total length of the number you want, and put this in the first value. Looks like you probably want %08.3f. Remember that the total width _includes_ the decimal point.

Best Wishes
assaad



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

PostPosted: Thu Oct 07, 2010 2:56 am     Reply with quote

Thank you for your fast response, it is ok now , I remember in C18 it was diffirent so Imy mind is mixed .However thank you ..
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