mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-25 14:01:29 -05:00
fix(curriculum): add rounding errors explanation to float lesson (#65957)
This commit is contained in:
@@ -178,6 +178,12 @@ print('Integer Exponentiation:', exp_ints) # Integer Exponentiation: 95116601380
|
||||
print('Float Exponentiation:', exp_floats) # Float Exponentiation: 614787626.1765089
|
||||
```
|
||||
|
||||
Sometimes, you might notice that the result of an operation involving floats has more decimal digits than expected. For example, the sum `0.1 + 0.2` equals `0.30000000000000004` instead of `0.3`.
|
||||
|
||||
This happens because numbers are stored in binary format, and some fractions cannot be represented exactly in binary. As a result, they are stored as finite approximations, in the same way the fraction `1/3` cannot be represented with a finite number of digits in decimal and is truncated after a certain number of its infinite digits (`0.33333...`).
|
||||
|
||||
This leads to small rounding errors.
|
||||
|
||||
Python also provides built-in functions for converting either numeric data or strings into integers or floats.
|
||||
|
||||
The `float()` function returns a floating-point number constructed from the given number:
|
||||
|
||||
Reference in New Issue
Block a user