Reputation: 55
I'm currently learning the C language and I'm having trouble in the double
multiplication topic.
I need to to print the original value and then the 2*value
of the double
.
double num = 34.39;
printf("Original value = %d, 2x original value = %d", num, num*2);
How do I make it so that the 2x value will be really 2x the original value?
Upvotes: 1
Views: 5720
Reputation: 385385
Your multiplication is not the problem.
Your printf
format string is. %d
is not for floating-point values, but for integers, so you're seeing nonsense resulting from your broken contract with the compiler.
double num = 34.39;
printf("Original value = %lf, 2x original value = %lf", num, num*2);
Upvotes: 8