Name | float |
||||
---|---|---|---|---|---|
Examples |
# Declare variable 'a' and assign it the value 1.5387 a = 1.5387 # Declare variable 'b' and assign it the value -2.984 b = -2.984 # Declare variable 'c' and assign it the sum of 'a' and 'b' c = a + b f = 0 for i in range(100000): f = f + 0.0001 # Bad idea! See below. for i in range(100000): # The variable 'f' will work better here, # less affected by rounding # Count by thousandths f = i / 1000.0 | ||||
Description |
Data type for floating-point numbers, a number that has a decimal point.
Floats are not precise, so avoid adding small values (such as 0.0001), as these may not always increment because of rounding error. If you want to increment a value in small intervals, use an int, and divide by a float value before using it. (See above example.) |
||||
Syntax | var = value | ||||
Parameters |
| ||||
Related |
int |
Updated on Tue Feb 27 14:07:12 2024.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License