it prints n = .000000Code:int main() { double n =.00000006; printf("n: %f", n); return 0; }
Any help is appreciated.
it prints n = .000000Code:int main() { double n =.00000006; printf("n: %f", n); return 0; }
Any help is appreciated.
Try %.8f
By default, %f only prints to 6 decimal places.
it's ironic considerate rarity patron of love higher knowledge engulfs me...
printf(3): formatted output conversion - Linux man page
Try using the %e or %g conversion formats as well
Try something like "%.15f" (see the field width and precision qualifiers in the manual).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thanks %.8f, this seemed to do the trick. how do i find the max value for float. I understand there is a float.h header but I'm a noob and I wasn't able to find anything on google how to print float_max value?
For the float type, FLT_MAX. For the double type, DBL_MAX. For the long double type (assuming a C99 compiler, possibly an extension with older compilers), LDBL_MAX. Each of those are macros are defined in <float.h>.
If I want more than 6 decimal places, will I have to specify for each instance or is there a way to change the default?
Also, is there a way for it to omit the extra zeroes in the end it would make it the output cleaner for me.
thanks guys.