it prints n = .000000Code:int main() { double n =.00000006; printf("n: %f", n); return 0; }
Any help is appreciated.
This is a discussion on Double precision is not correct within the C Programming forums, part of the General Programming Boards category; Code: int main() { double n =.00000006; printf("n: %f", n); return 0; } it prints n = .000000 Any help ...
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.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
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>.
Right 98% of the time, and don't care about the other 3%.
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.