# Problem with printing float precision values.

• 11-22-2012
vebi1000
Problem with printing float precision values.
Hi,

It seems simple problem for programmers but for me its complicated.

I am using CodeVision compiler. I am writing code in c language. I am trying to print float value with up to 10 digits precision. I have tried using "%.10f" but it is printing only six precision digits, even with "%.f". i know "%.f" will print six precision digits.
Code:

```float c, xc=50800.287F, w, f=125000.0F; w=2*3.14*f; c=1/w*xc;  /which is equal to =1/39878000000=2.507e-11.```
I want to print that "c" value. I have tried to print using the fallowing statement.
Code:

`printf("capacitance value is : %.12f", c);`
But from the above statement i getting value like "0.000000".

Please suggest how can i print that C value.

I tried to use "double variable but my CodeVision is not supporting double variables. help me please.
• 11-22-2012
std10093
The code bellow is going to print a value with 12 digits precision
Code:

```#include <stdio.h> int main(void) {   double c, xc=50800.287F, w, f=125000.0F;   w=2*3.14*f;   c=1/w*xc;   printf("capacitance value is : %.12f\n", c);   return 0; }```
Are you sure that double is not supported?I mean it is a primitive type of C.... What error do you get? :)

EDIT : Ok, i think you have a logical error.
What you want is
Code:

`c=1/(w*xc);`
but you have
Code:

`c=1/w*xc;`
The problem is that in your code the code will be executed like this : (1/w)*xc

Mind also that you need at least 11 digits precision otherwise you will see only zeros.

And with a second thought i found out that float is ok.So i tried it...
Code:

```#include <stdio.h> int main(void) {   float c, xc=50800.287, w, f=125000.0;   w=2*3.14*f;   c=1/(w*xc);   printf("capacitance value is : %.12f\n", c);   return 0; }```
and the output was
Code:

```Macintosh-c8bcc88e5669-9:~ usi\$ ./px capacitance value is : 0.000000000025 Macintosh-c8bcc88e5669-9:~ usi\$```
Hope this helps :)