sprintf and float

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

sprintf and float

2,309 次查看
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?

标签 (1)
0 项奖励
4 回复数

222 次查看
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 项奖励

1,372 次查看
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

1,372 次查看
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 项奖励

1,372 次查看
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 项奖励