how to make the output 0.0000000001

I want to convert energy from joules(J) to gigajoules(GJ)
1 joules = 0.000000001 GJ
and i use this--->

printf("\nEnter the value of length to be converted: ");
scanf("%f",&value);
printf("\nEnter the unit of value entered (J/kJ/MJ/GJ/cal) : ");
scanf("%s",&unit1);
printf("\nEnter the unit to convert value to(J/kJ/MJ/GJ/cal) : ");
scanf("%s",&unit2);
if((strcmp("J",unit1) == 0)&&(strcmp("GJ",unit2)==0))
ans=(value/(float)1000000000);
printf("\n%f %s is equal to %f %s\n",value,unit1,ans,unit2);

when I try to print the "ans", it turns out to be like this-->

1.000000 J is equal to 0.000000 GJ

what I want is-->

1.000000 J is equal to 0.000000001 GJ

Please help me T_T Or u can suggest to me a good idea
By default printf with %f displays a limited number of digits after the decimal point (I think 6). You can try:

1
2
3
4
5
6
7
#include<stdio.h>
int main()
{
float a=1./(float)1000000000;
printf("%.9f\n",a);
return 0;
}


But this will always display a lot of digits. A much better solution is to use scientific notation, %e instead of %f
ats15,
Thank you! It works!:)
Topic archived. No new replies allowed.