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 113 views
1 answer 130 views
1 answer 121 views
1 answer 134 views
1 answer 144 views
1 answer 151 views
...