gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
Printf with a signed int16 and "decimal point" ? |
Posted: Mon Jan 03, 2011 10:39 am |
|
|
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 |
|