Thursday, 15 May 2014

c - scanf - limit decimal places while reading -


I know how to limit printing values ​​to decimal and integer in printf (% xx), in my scenario I I want to implement it

So is there any way to limit the number of decimal in the floating point value while reading the scanf function?

I tried the following, to show any errors while compiling, but the value is always 0

  float F1; . . Scanf (".% 3F", & amp; f1); Printf ("% 3.3f \ n", f1);  

If you check the document, then it says

:

The format specifier for scanf follows this prototype:

% [*] [width] [length] specifier

and compare it comparison:

A format specifier follows this prototype:

% [flags] [Width] [. Exact] [Length] specifier

You will see that if there is no precise in scanf, then I think that the circular (or the cut of digits) Casting for int) is the only way.


No comments:

Post a Comment