How to count the number of digits in a double with C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    double d = 23445.938076;
    char str[16] = "";
     
    sprintf(str, "%.6lf", d);
    
    int digits = strlen(str) - 1;
 
    printf("%d", digits);
     
    return 0;
}
  
   
   
   
/*
run:
   
11
 
*/

 



answered Nov 12, 2023 by avibootz

Related questions

1 answer 106 views
1 answer 122 views
1 answer 112 views
1 answer 125 views
1 answer 136 views
1 answer 142 views
...