Programming Fundamentals/FloatingPoint Data Type
OverviewEdit
A floatingpoint data type uses a common representation of real numbers as an approximation, which is essentially a tradeoff between range and precision. For this reason, floatingpoint computation is often found in systems that include very small and very large real numbers, which require fast processing times. A number is, in general, represented approximately to a fixed number of significant digits and scaled using an exponent in some fixed base such as 10.^{[1]}
DiscussionEdit
The floatingpoint data type is a family of data types that act alike and differ only in the size of their domains (the allowable values). The floatingpoint family of data types represents number values with fractional parts. They are technically stored as two integer values: a mantissa and an exponent. The floatingpoint family has the same attributes and acts or behaves similarly in all programming languages. They can always store negative or positive values thus they always are signed; unlike the integer data type that could be unsigned. The domain for floatingpoint data types varies because they could represent very large numbers or very small numbers. Rather than talk about the actual values, we mention the precision. The more bytes of storage the larger the mantissa and exponent, thus more precision.
Language  Reserved Word  Size  Precision  Range 

C++  float

32 bits / 4 bytes  7 decimal digits  ±3.40282347E+38 
C++  double

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
C#  float

32 bits / 4 bytes  7 decimal digits  ±3.40282347E+38 
C#  double

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
Java  float

32 bits / 4 bytes  7 decimal digits  ±3.40282347E+38 
Java  double

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
JavaScript  Number

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
Python  float()

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
Swift  Float

32 bits / 4 bytes  7 decimal digits  ±3.40282347E+38 
Swift  Double

64 bits / 8 bytes  15 decimal digits  ±1.79769313486231570E+308 
When converting operations with floatingpoint values, there may be more decimal places than you want. We can use the round function to limit the number of decimal places displayed. For example, round(1.12356,2) gives 1.12.^{[2]}
Key TermsEdit
 double
 The most often used floatingpoint family data type used.
 mantissa exponent
 The two integer parts of a floatingpoint value.
 precision
 The effect on the domain of floatingpoint values given a larger or smaller storage area in bytes.