C - Format floating-point number width and decimal width

Introduction

By placing 2.1 between the % and the f, you direct printf() to format the output with two digits to the left of the decimal and one digit to the right.

printf("The value %2.1f is an float.\n",98.6); 

Demo

#include <stdio.h>

int main()// ww  w. ja v  a  2  s .c o m
{
    printf("The value %2.1f is an float.\n",98.6); 
    return(0);
}

Result

Related Exercise