sprintf and float

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sprintf and float

2,983 Views
andreaskneissl
Contributor II

I am working wih LpcXpresso IDE and have problems to use the function sprintf() with float conversion. A lot of hints are available in the internet (e.g. uses -u _printf_float). But I do not know, how to handle this. Can anybody give me a solution?

Labels (1)
0 Kudos
Reply
4 Replies

896 Views
rjleiser
Contributor II

For me I found something in the linker settings. Project Properties.

checkboxes for printf and scanf floats.

- this seemed to work for sprintf too.

rjleiser_0-1711629896315.png

 

0 Kudos
Reply

2,046 Views
lpcxpresso_supp
NXP Employee
NXP Employee

So is your project configured to use Redlib, Newlib or NewlibNano as your selected C library?

What are Redlib and Newlib? 

If you are using Redlib, then make sure you haven't got CR_INTEGER_PRINTF symbol defined:

Using printf() 

And if you are using NewlibNano, then make sure you have "Enable printf/scanf float" enabled in Project properties:

Newlib-Nano Support 

If you need further assistance, then please confirm the version of LPCXpresso IDE that you are using, and export and post an example project that shows up your problem:

https://community.nxp.com/message/630625 

Regards,

LPCXpresso Support

2,046 Views
andreaskneissl
Contributor II

Here is the code example:

char temp[20];

float wert=1.234

sprintf(temp,"%1.3f",wert)
The result is an empty string. If I use an integer wert and format it with "%d" I get the right string.

0 Kudos
Reply

2,046 Views
converse
Senior Contributor V

Very hard to give a solution if you don't describe the problem. Please describe exactly your problem and show us the code you are using.

0 Kudos
Reply