c - print double in scientific format with no integer part -


a simple problem can't documentation kind of format: want print float in fortran scientific notation, integer part being zero.

 printf("%0.5e",data); // gives 2.74600e+02 

i want print this:

 .27460e+03 

how can result clean possible?

if care integer part being 0 , not leaving out 0, i.e. if you're fine 0.27460e+03 instead of .27460e+03 similar this:

#include <stdio.h> #include <stdlib.h>  void fortran_printf();  int main(void) {         double num = 274.600;         fortran_printf(num);          exit(exit_success); }  void fortran_printf(double num) {         int num_e = 0;         while (num > 1.0) {                 num /= 10;                 num_e++;         }          printf("%.5fe+%02d", num, num_e); } 

otherwise have take detour on strings. note code above meant started. doesn't handle involved cases.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -