David Perreault

float to string

Discussion created by David Perreault on Jan 12, 2012
Latest reply on Jan 20, 2012 by David Perreault

Hi,

 

I have an issue to convert a float to a string with the Coldfire MCF52259. Here what I am trying to do:

 

char str[10];

float fval = 1201 / 10;

sprintf (str, "%3.1f\n", fval);

 

The debugger shows that fval is 120.100. This is what I expect to see. But "str" is not set correctly. If I do the same thing with an integer, there is no problem:

 

char str[10];

int val = 1201

sprintf (str, "%d\n", val);

 

 

What I am doing wrong?

 

Thanks in advance

Outcomes