AnsweredAssumed Answered

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

Question asked by Sandro Bastos on Feb 14, 2014
Latest reply on Aug 31, 2015 by Karina Valencia Aguilar

If I use a printf/sprintf format for float like "%3.0f" it should print the float without the fractional part.

 

Ex.: n = 2.718     -> output should be: 2

 

If I use the format "%3.1f", the output should be 2.7

 

The problem I found in MQX 4.02 is, when I use the first example, "%3.0f", the output is 2.7, instead of 2

Exactly the same behaviour if I use "%3.1f".

 

It seems to me to be a bug but at "io_dopr.c" there is a code that force this situation; I commented the code (as seen below) and now it is working fine.

 

Could someone explain me this?

I do not like to work with a modified MQX.

Is there anyother solution for this issue?

 

thank you all...

 

 

         case 'f':

         case 'F':

            if (! prec_set) {

               prec = 6;

            } /* Endif */

           

           

//??            /*

            if (prec == 0) {

               prec = 1;

            }

            */

           

Bruno Castelucci

Rene Kolarik

Karina Valencia Aguilar          

Outcomes