printf float format like "%0.02f" does not work

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

printf float format like "%0.02f" does not work

1,752 Views
sandrobastos
Contributor IV

Hi Rene,

https://community.freescale.com/message/560857?et=watches.email.thread#560857

18 months later this discussion, another float format problem was found.

I'm still using MQX 4.1.1, with the corrections discussed in this post.

I'm using the float format "%0.02f" to obtain outputs of type "x.yz".

     1- If the number is, for example, 1.234, I get "1.23" ---> that's right.

     2- If the number is shorter than one and greater than 0.1, for example, 0.123, the output string is "012" (without dot) and not "0.12".

     3- If the number is shorter than 0.1, e.g. 0.05, it also works giving an "0.05" string.

Resuming, the wrong result is for the range:    0.1 <=  x < 1.0

Another workaround or correction I could apply?

thank you,

sandro

Rene Kolarik

Karina Valencia Aguilar

Bruno Castelucci

5 Replies

1,106 Views
kaif
Contributor I

Hi.

I'm having the same problems here.

Kai

0 Kudos

1,106 Views
dshimizu
NXP Employee
NXP Employee

Hello Sandro,

On MQX for Kinetis when I try:

    float pi = 3.1415;

    printf("The Pi number is: %2.2f\n",pi);

    printf("And a tenth of Pi is: %2.2f\n",pi/10);

I got on the terminal:

The Pi number is: 3.14

And a tenth of Pi is: 0.31

Can you make a test trying to use %1.2f instead?

0 Kudos

1,107 Views
sandrobastos
Contributor IV

Hi Denis,

I've just run your example and got a wrong output (the same for "%2.2f" and "%1.2f"):

The Pi number is: 3.14

And a tenth of Pi is: 031

Remember I'm using a patched MQX4.1.1 (see the link at the top of this post); maybe the patches are causing this problem.

thank you and best regards,

sandro

0 Kudos

1,107 Views
rendy
NXP Employee
NXP Employee

Hello, I will check this and provide a patch soon.

1,107 Views
sandrobastos
Contributor IV

Hi Rene,

the old bug, cited in the top link of this post, is still present in MQX 4.2 :(

so we have to apply that patches that brings this new bad behavior.

regards,

sandro

0 Kudos