Two decimal places using printf( )

What you want is %.2f, not 2%f.

Also, you might want to replace your %d with a %f ðŸ˜‰

#include <cstdio>
int main()
{
printf("When this number: %f is assigned to 2 dp, it will be: %.2f ", 94.9456, 94.9456);
return 0;
}

This will output:

When this number: 94.945600 is assigned to 2 dp, it will be: 94.95

What you want is %.2f, not 2%f.
Also, you might want to replace your %d with a %f 😉
#include <cstdio> int main() { printf("When this number: %f is assigned to 2 dp, it will be: %.2f ", 94.9456, 94.9456); return 0; }
This will output:
When this number: 94.945600 is assigned to 2 dp, it will be: 94.95

Leave a Comment