[C] Floating Point Type

Floating Point Type Print

#include <stdio.h>

int main(void)
{  
    printf("%lf\n", 123.45); // 123.450000
    printf("%.2lf\n", 123.45); // 123.45
    printf("%.0lf\n", 123.45); // 123
    printf("%.lf\n", 123.45); // 123

    return 0;
}
  • %lf     : Round off to the 7th decimal place.
  • %.2lf : Round off to the 3th decimal place.
  • %.0lf  : Round off to the first decimal place.
  • %.lf    : same with %.0lf.

Tags:

Categories:

Updated: