PyDocs

Nav

Python Runtime Services

float

  • float(number=0.0, /)
  • float(string, /)
Convert a string or number to a floating-point number, if possible.
Changed in 3.6, 3.7, 3.8
  • 3.6: Grouping digits with underscores as in code literals is allowed.
  • 3.7: The parameter is now positional-only.
  • 3.8: Falls back to __index__() if __float__() is not defined.
Members of float

a

as_integer_ratio
Return a pair of integers, whose ratio is exactly equal to the original float.

f

from_number
Convert real number to a floating-point number.
fromhex
Create a floating-point number from a hexadecimal string.

h

hex
Return a hexadecimal representation of a floating-point number.

i

is_integer
Return True if the float is an integer.
1 Example
>>> float('+1.23')
1.23
>>> float('   -12345\n')
-12345.0
>>> float('1e-003')
0.001
>>> float('+1E6')
1000000.0
>>> float('-Infinity')
-inf
from the Python docs
See Also
No see-alsos for builtins/float
0 Notes
No notes for float