float type in Python represents the floating point number. Float is used to represent real numbers and is written with a decimal point dividing the integer and fractional parts. For example, 97.98, 32.3+e18, -32.54e100 all are floating point numbers.
Python float values are represented as 64-bit double-precision values. The maximum value any floating-point number can be is approx 1.8 x 10308. Any number greater than this will be indicated by the string
inf in Python.
Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. For example, the decimal fraction 0.125 has value 1/10 + 2/100 + 5/1000, and in the same way the binary fraction 0.001 has value 0/2 + 0/4 + 1/8. These two fractions have identical values, the only real difference being that the first is written in base 10 fractional notation, and the second in base 2.
Unfortunately, most decimal fractions cannot be represented exactly as binary fractions. A consequence is that, in general, the decimal floating-point numbers you enter are only approximated by the binary floating-point numbers actually stored in the machine.
float type implements the
numbers.Real abstract base class. Returns an expression which is converted into floating point number.
float also has the following additional methods:
float.as_integer_ratio() : Returns a pair of integers whose ratio is exactly equal to the actual float having a positive denominator.In case of infinites, it raises overflow error and value errors on Not a number (NaNs).
7 / 2
float.is_integer() : Returns True in case the float instance is finite with integral value, else, False.
True False True
float.hex() : Returns a representation of a floating-point number as a hexadecimal string.
float.fromhex(s) : Returns the float represented by a hexadecimal string s. String s may have leading and trailing whitespaces.
Note : float.hex() is an instance method, but float.fromhex() is a class method.
- Python - Convert Float String List to Float Values
- Convert String float to float list in Python
- float() in Python
- Python | Float Layout in Kivy
- Python | Min/Max value in float string list
- Python | sympy.Float() method
- Python | Check for float string
- Python | Convert tuple to float value
- Python | Average of Float Numbers
- Convert String to Float in Python
- Python - Resolve Float Keys in Dictionary
- Python | List of float to string conversion
- Python - Summation of float string list
- Python - Convert Float to digit list
- Python | Sort a tuple by its float element
- Python - Produce K evenly spaced float values
- Python | Filter out integers from float numpy array
- Python | Ways to sort list of float values
- Python - Filter float strings from String list
- Python | Convert Joint Float string to Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.