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()// w  w w.jav a2 s .  c  o m
{
    printf("The value %2.1f is an float.\n",98.6); 
    return(0);
}

Result

Related Exercise