# Thread: Double Precision Problem

1. ## Double Precision Problem

Hello guys,
I'm new on C. And I have problems with double precision.

Whenever I build & run the code, the output is:
mass of electron is -0.000000
(I use Code::Blocks)

Code:
#include <stdio.h>
#include <stdlib.h>

main()
{
long double me=9.1094e-31;
printf("mass of electron is %Lf\n",me);
}
With my best regards, and thanks

2. You need to print out more decimal places. C only uses 6 places after the decimal by default. Try "%.35Lf". That gives you 35 digits after the decimal. Adjust as needed.

EDIT: Also, check out this article (link). Understanding the limits of floating point precision will be very handy when dealing with scientific calculations like yours, since you are working with such large exponents (whether positive or negative).

3. Problem was solved. Thank you

Code:
#include <stdio.h>
#include <stdlib.h>

main()
{
double me=9.1094e-31;
printf("mass of electron is %.40lf\n",me);

}

4. Check the edit in my previous post, there's a very useful link there.

5. For extra fun, try "%e" instead and see what happens.

Popular pages Recent additions