![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jruibarroso
Joined: 07 Jan 2006 Posts: 64 Location: Braga
|
need help about printing a decimal number |
Posted: Tue Mar 21, 2006 4:22 am |
|
|
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 !! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Mar 21, 2006 4:59 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Calamar
Joined: 07 Sep 2003 Posts: 60 Location: Buenos Aires (Argentina)
|
|
Posted: Wed Mar 22, 2006 12:17 pm |
|
|
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) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|