hello this is anu. i am working with C++ lately, am tired with the confusion with the float type. am using turbo c++. please could someone explain the working of float type.
int v/s float
Collapse
X
-
1. You should only use float types if you really need that much range or you actually require floating point arithmatic, if an integer type (long) will do then use that type.
2. Floating point types do not store exact values, they store approximations, because of this you can not rely on them having an exact value, you need to make sure that you program handes rounding correctly when you display them.
3. Do not use floating point types as a control variable because you can not rely on them having an exact value.
So basically a floating point type is useful for holding really large or small numbers or numbers with decimal places but should only be used for calculation or display purposes.
Integer types have exact values but limited range, the standard conversion of float to integerjust lops off the decimal part. Integer types should be your type of choice unless you have a specific reason for using floating point types.
Comment