- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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 /?
Let us know if this works for you.
-Sergio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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 http://www.codeforwin.in/2015/05/list-of-all-format-specifiers-in-c.html and try the options for double data types.
-Sergio

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page