+ 4
What does float and double mean? What would they be used for?
8 Answers
+ 11
What does float and double mean? What would they be used for?
Both are real numbers along with the variable type decimal.
float: a variable type that represents single-precision floating-point numbers that are 32 bits in size and have 7 digits of precision.
double: a variable type that represents double-precision floating-point numbers. double require twice the memory(64bits) and ~twice the precision(15-16) of float variables.
This allows double variables to store larger numbers with greater precision(the numbers to the right of the decimal point.) compared to float.
Want a more precise real number use double over float. Want an even more precise real number, use decimal over both double and float.
Floating-point numbers (double&float) are not always 100% correct since their precision ends at a certain point. They can still be useful in certain scenario where you need a rough amount that's close to the exact amount.
Say you want to take the temperature outside and only want to know if it's 82.3 degrees, when it's actually 82.3657654895647568 degrees. Then float or double would be good for this example because you don't need or want to know the exact temperature.
However, let's say we're talking about monetary amounts, double and float would be less suited for this since we want a precise amount. To most this would be extreme but today companies make big money off taking a hundredth or a thousandth of a percent per penny per transaction. Considering the unimaginable amount of money and transactions mega companies perform, knowing the exact amount is huge business for them.
Finally, when using a floating-point variable, double is normally preferred over float due to it's better accuracy.
+ 3
float is a decimal number.
1.473637
Double can hold more decimals than float. And takes more memory.
What haytham said with true or false applies to boolean, or bool.
+ 2
you're welcome
+ 2
float and double are nearly seems to be same but double allows larger numbers to store the numbers in real form (ex 1.7076)
+ 1
Thx
0
thanks andreas sorry drew
- 2
double =3:4 2:4 x:y ........
- 6
float = true or false