Floating point number is a numeric data type used to represent real-number approximations.
Floating point values can represent fractions and very large or very small numbers, but they are not exact for all decimal values.
For example:
print(0.1 + 0.2)This may print a value like 0.30000000000000004 because many decimal fractions cannot be represented exactly in binary floating point.
Common floating point types include:
float32float64double
Floating point numbers are useful for measurement, simulation, graphics, and scientific computation. They are usually a poor choice for money unless the rounding behavior is carefully controlled.
Anki
id: floating-point-definition deck: Computer Science::Data Types tags: data-types floating-point
Q: What is a floating point number? A: A floating point number is a numeric data type used to represent real-number approximations.
id: floating-point-precision deck: Computer Science::Data Types tags: data-types floating-point precision
Q: Why can 0.1 + 0.2 produce an unexpected floating point result?
A: Many decimal fractions cannot be represented exactly in binary floating point, so arithmetic can produce small precision errors.