AnsweredAssumed Answered

sprintf

Question asked by Klayton Jones on Dec 15, 2011
Latest reply on Feb 4, 2014 by alfredogualdron

I have a quick (and probably dumb) question on sprintf for the kinetis MCU.  I am trying to use sprintf on a floating point number and have had trouble (yes I realize sprintf is huge when used on floats).  It works fine with integers but not floats.  What is the trick to get it to work? Here is an example of how I am formatting the string:

 

#include <stdlib.h>

#include <stdio.h>

 

float test = 10.123;

sprintf(tempString, "%2.1f", test);

 

When I have used sprintf with other MCU's (microchip) this would spit out "10.1" to my display. This prints out "%2.1f" when I use it with CodeWarrior / kinetis.  What am I missing?  I am using CodeWarrior 10.1 with all the latest updates/patches.  

 

Thanks!

Outcomes