3 Replies Latest reply on Oct 7, 2016 2:39 PM by Intel_Alvarado

    How to print double value ?

    mark_kram

      How can I print double value 2.345 I try to use f and e value but effect was as below:

       

      double a = 2.345;

       

      QM_PRINTF("VCC: %.2f \n", a);          print: "VCC: %.2f"

      QM_PRINTF("VCC: %3.2f \n", a);        print: "VCC: %3.2f"

      QM_PRINTF("VCC: %e \n", a);            print: "VCC: %e"

       

      Br's.

        • 1. Re: How to print double value ?
          Intel_Alvarado

          Hi mark_kram,

           

          I believe it’s because of the format you’re using in the print statement. Can you try to use %lf instead of %2f?

          Let us know if this works for you.

           

          -Sergio

          • 2. Re: How to print double value ?
            mark_kram

            Hi Alvarado,

             

            the effect of below code:

            double a = 2.345;

            QM_PRINTF("VCC:  %lf \n", a);

            clk_sys_udelay(300000);

             

            is:

            VCC:  %f

            so maybe you have other idea ?

             

            Of course it is not the problem resolve this situation (for example code below) but I just wondering maybe it it possible to write shorter code and base it on double type of data:

             

            resistor = (resistor/(NUM_SAMPLES_POLLED/2));

            fotoresistor = (fotoresistor/(NUM_SAMPLES_POLLED/2));

            uint32_t fotoR_light_percent = fotoresistor*(100.0/ADC_RESOLUTION);

            uint32_t fotoR_voltage = fotoresistor*(3300.0/ADC_RESOLUTION);

            uint32_t resistor_percent = resistor*(100.0/ADC_RESOLUTION);

            uint32_t resistor_voltage = resistor*(3300.0/ADC_RESOLUTION);

             

            QM_PRINTF("\nResistor med.: %d\n",(unsigned int)resistor);

            QM_PRINTF("Fotores. med.: %d\n",(unsigned int)fotoresistor);

            QM_PRINTF("Light %d%% ADC:(%d,%d V)\n", (int)fotoR_light_percent, (int)fotoR_voltage/1000, (int)fotoR_voltage%1000);

            QM_PRINTF("Res. sett.: %d%% vol. on res. %d,%d V\n", (int)resistor_percent, (int)resistor_voltage/1000, (int)resistor_voltage%1000);

             

             

            Best regards,

            Frank.

            • 3. Re: How to print double value ?
              Intel_Alvarado

              Hi Frank,

               

              I found a list with the format specifiers that are used in C. Take a look at http://www.codeforwin.in/2015/05/list-of-all-format-specifiers-in-c.html and try the options for double data types.

               

              -Sergio