How to print a float variable?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to print a float variable?

Jump to solution
2,303 Views
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 Kudos
1 Solution
561 Views
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).

 

View solution in original post

0 Kudos
5 Replies
561 Views
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 Kudos
561 Views
d_vara
Contributor III

Ok,Monday I will probe it.

 

Very thanks.

0 Kudos
561 Views
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 Kudos
562 Views
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 Kudos
561 Views
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 Kudos