View previous topic :: View next topic |
Author |
Message |
assaad
Joined: 09 Dec 2009 Posts: 37
|
printf and float number |
Posted: Thu Oct 07, 2010 1:56 am |
|
|
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: 19538
|
|
Posted: Thu Oct 07, 2010 2:45 am |
|
|
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
|
|
Posted: Thu Oct 07, 2010 2:56 am |
|
|
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 .. |
|
|
|