How to print a float variable?

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

How to print a float variable?

跳至解决方案
2,621 次查看
d_vara
Contributor III

Hello.

In my program I want print or save in file some variables.

When I program this above,it does not work.

 

float i=1.234;

printf ("Variable= %f", i);

 

Then, I need to program this:

float i=1.234;

int j;

i=1.234*1000;

j=i/1000;

i=i-(j*1000);   //the operator % does not work.

printf ("Variable= %d.%d",j,i); //It work!

 

This situation occurs in printf and sprintf.

 

Anyone can solve it?

Thank you.

0 项奖励
1 解答
879 次查看
EAI
Contributor IV

You will need to add the file mqx\source\fio\io_fp.c to the psp project as well (it should have been there).

 

在原帖中查看解决方案

0 项奖励
5 回复数
879 次查看
EAI
Contributor IV

Refer to page 128 of the MQX User's manual.

Add:

#define MQX_INCLUDE_FLOATING_POINT_IO 1

to user_config.h (make sure you add it to the correct file in the config directory, not in the lib directory).

Rebuild the PSP library. then rebuild the application.

 

Note: This will require additional stack space for the tasks calling printf.

0 项奖励
879 次查看
d_vara
Contributor III

Ok,Monday I will probe it.

 

Very thanks.

0 项奖励
879 次查看
d_vara
Contributor III

I have just to probe it.

I rebuild all libreries.

But when I recompile hvac_demoEVB for 52259, I can read thetwo next errors:

undefined _io_dtoe

undefined _io_dtof

 

both referenced from "io_do_print"

 

 

 

Thanks

0 项奖励
880 次查看
EAI
Contributor IV

You will need to add the file mqx\source\fio\io_fp.c to the psp project as well (it should have been there).

 

0 项奖励
879 次查看
d_vara
Contributor III

Yes. It is the solution.

 

I use MQX 3.2 with codewarrior 7.1.2.

 

I make this changes, and now it is work.

 

Thank you.

0 项奖励