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

visualisation float

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



Joined: 07 Oct 2003
Posts: 7

View user's profile Send private message

visualisation float
PostPosted: Thu Feb 10, 2005 2:52 am     Reply with quote

Hello,

What is the best way to print a negative value between -1 and 0.

I have the value -0.5 so i print it as:

printf( "%01.1f%", data );

the output is: -.5

i tried several possibilities to print the right float (such as: %2.1f e.g.)
but nothing helps.

Is there another way to print the right value?
Ttelmah
Guest







PostPosted: Thu Feb 10, 2005 3:39 am     Reply with quote

There are two parts to this. The first is to get the format right, and the second is to hope that CCS handles it correctly!. Neither of the formats you post, would be 'correct', for a leading '0'. The number to the right of the DP, is the 'precision', while the number left of the DP, is the 'minimum field width', or the number of digits after the DP for a float. Now in the first case, you have specified a 'width' of only one digit, and this is filled with the '5', so there is no leading 0. In the second example, you have lost the 'leading zero' flag.
So the supposedly 'correct' format, would be:
printf("%02.1f",data);
Note that you do not want the trailing % sign (this tells the compiler that the next character is another control sequence). If you want to display the '%' symbol after the numbers, you need '%%'.
However the CCS compiler (unfortunately), has some problems with handling leading zeros correctly. This varies with compiler versions, so if yours does not work properly, you would have to bodge round, possibly by printing the data to a string and adding the zero, or by testing for the number being ngative, and printing the '-0', then printing the -ve value for the rest of the data...

Best Wishes
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