C: Suppose we have a floating point number with higher precision say 12.126487687 and we wish it to be printed with only precision up to two decimal places. How can I do this?
Suppose we have a floating point number with a higher precision say 12.126487687 and we wish it to be printed with only precision up to two decimal places. How can you do this?
This can achieved through the use of suppression char '*' in the format string of printf( ) which is shown in the following program.
main( )
{
int p = 2 ;
float n = 12.126487687 ;
printf ( "%.*f",p, n ) ;
} 



Comments
Log in or create a user account to comment.