You can solve this problem using format specifiers in C.
For example, let's say that you want to print only three places after the decimal place, you can make your printf as follows:
printf("%.3lf", dub);
If the value is double dub = .0137; the output will be 0.014
This will fix the problem with your 2nd case if you want to print more precision that you could write:
printf("%.8lf", dub);
Your result for double dub = 0.00265721; will be then 0.00265721
The case for% g works in the same way, except for the number on the left, which is included in the calculation. If you want a C ++ version (the lower accuracy I assume), then your code will look like this:
double dub = .0000324769; printf("%.5g", dub);
What gives 3.2477e-05
Lucas derraugh
source share