I'm trying to write a number to two decimal places using printf()
as follows:
#include <cstdio>
int main()
{
printf("When this number: %d is assigned to 2 dp, it will be: 2%f ", 94.9456, 94.9456);
return 0;
}
When I run the program, I get the following output:
# ./printf
When this number: -1243822529 is assigned to 2 db, it will be: 2-0.000000
Why is that?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…