fork download
  1. #include <stdio.h>
  2.  
  3. #define FLOAT_PRECISION 2
  4.  
  5. int main(void)
  6. {
  7. double lbfl = 0.150000006f;
  8.  
  9. char float_format[10] = { '\0' };
  10. sprintf(float_format, "%%.%dg", FLOAT_PRECISION);
  11.  
  12. printf("old lbfl = %.15f\n", lbfl);
  13.  
  14. char reg[10] = { '\0' };
  15. sprintf(reg, float_format, lbfl);
  16. sscanf(reg, "%lf", &lbfl);
  17.  
  18. printf("new lbfl = %.15f\n", lbfl);
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
old lbfl = 0.150000005960464
new lbfl = 0.150000000000000