Next / Previous / Contents / TCC Help System / NM Tech homepage

7.4. Type float: Floating-point numbers

Values of this type represent real numbers, with the usual limitations of IEEE-754 floating point type: it cannot represent very large or very small numbers, and the precision is limited to only about 15 digits. For complete details on the IEEE-754 standard and its limitations, see the Wikipedia article.

A floating-point constant may be preceded by a “+” or “-” sign, followed by a string of one or more digits containing a decimal point (“.”).

For very large or small numbers, you may express the number in exponential notation by appending a letter “e” followed by a power of ten (which may be preceded by a sign).

For example, Avogadro's Number gives the number of atoms of carbon in 12 grams of carbon12, and is written as 6.0221418×1023. In Python that would be “6.0221418e23”.

Please note that calculations involving float type are approximations. In calculator mode, Python will display the numbers to their full precision, so you may see a number that is very close to what you expect, but not exact.

>>> 1.0/7.0
0.14285714285714285
>>> -2*-4.2e37
8.4000000000000004e+37