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 support@ccsinfo.com

Printf with a signed int16 and "decimal point" ?

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



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

Printf with a signed int16 and "decimal point" ?
PostPosted: Mon Jan 03, 2011 10:39 am     Reply with quote

The compiler supports a fake decimal point for unsigned int8 printing by using the "%w" format specifier in the printf routine. Unfortunately, it is only for an unsigned 8bit integer. Has anybody got a easy version for handling signed int16's ? I know I could convert to a float and print that way, but it seems silly to convert to float just to display a negative temperature (all my calculations are in deg C * 10 since the sensor gives me 10mv/deg C). The "w" option almost does it and if it handled int16, it would be fairly easy to get around with a test for <0, set a char to the '-' (or ' ' if positive) and use abs(value) for the print. Several ways around it, just wondered if others had a simple solution (I could not find search terms that didn't either return the whole forum or nothing ... time for coffee !! )

Thanks
mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
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