Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C language how to format a double to 2 digits after the decimal point? [duplicate]

Tags:

c

formatting

Possible Duplicate:
Limit floating point precision?

In C language, I need to format a number to 2 digits after the decimal point from user input

For example:

 float x ; 
 printf("Enter number");

Let's suppose the user enters 4.54234635

I need to print and process in the whole program: 4.54

Thanks advance

like image 418
Saeed ALSferi Avatar asked Nov 27 '22 07:11

Saeed ALSferi


1 Answers

scanf("%.2f",&x);

And i think that will solve a problem

like image 182
Dmitry Zheshinsky Avatar answered Dec 15 '22 07:12

Dmitry Zheshinsky