How to set precision of a float
You can't do that, since precision is determined by the data type (i.e. float
or double
or long double
). If you want to round it for printing purposes, you can use the proper format specifiers in printf()
, i.e. printf("%0.3f\n", 0.666666666)
.
Floats have a static, fixed precision. You can't change it. What you can sometimes do, is round the number.
See this page, and consider to scale yourself by powers of 10. Note that not all numbers are exactly representable as floats, either.
You can't. Precision depends entirely on the data type. You've got float
and double
and that's it.