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

trouble getting leading zero's or spaces to show

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



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

trouble getting leading zero's or spaces to show
PostPosted: Tue Feb 24, 2009 10:15 am     Reply with quote

Hi There,
I have a PIC18F2580 attached to a 20x4 hitachi LCD, it all works fine and my code is pretty stable, but I am unable to display the leading zero's or spaces of a floating point number.

The information displayed should be lined up but its appears to not be.

the code I am using is:
Code:
lcd_gotoxy(15,4);
printf(lcd_putc,"%04.1f",temp);


temp is a float, currently set at 16.0

here is my current display:

Code:
11Kw    ALARM 50.0Hz
    Ph1   Ph2   Ph3
V 232.3 238.9 243.6
I 16.2  16.0  16.0


I have tried it without the 0, and it just shows the same value and is very much left aligned to column 15.
I would like to have all the decimal points line up on the screen

the value on the line above it is 243.6 but the decimal for 16.0 is under the 3.

I have tried different number formats but with no avail
I am using IDE and PCH version 4.071, I know CCS can be quirky at times, is this one of them?

thanks
Ttelmah
Guest







PostPosted: Tue Feb 24, 2009 11:24 am     Reply with quote

Your main problem, is that the number in front of the DP, in the format, is too small. In C, this is the _total field width_, not the number of digits in front of the decimal. So for your numbers with three leading digits (238.9 for example), this number needs to be 6, not 4. 6, since a numeric field in C, always has one leading space. So you need space, three digits, decimal, one digit. Total 6 characters wide.
The '0', _will_ appear, once the field is wider than the output. Leading zeros are _only_ displayed, when the number needs less digits than the field. So with the 6 used, you will get a leading zero, but at present, you won't.

Best Wishes
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Tue Feb 24, 2009 10:48 pm     Reply with quote

thanks Ttelmah,

That worked a treat, now it shows correct spacing.

it's this sort of thing you miss when you teach yourself programming languagees Smile
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