Use the format specifier %.2f
for 2 digits of precision. Similarly use %.3f
for 3 digits. For future reference, here are the printf
format specifiers.
#include <stdio.h>
int main()
{
printf("%.2f\n", 0.005); // prints 0.01
printf("%.2f\n", 0.004); // prints 0.00
}