You can specify the floating-point precision to output using the format % :
#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { float num = 3.166667; printf("%.2f", num); return 0; }
output:
3.17