Skip to content

Decimal numbers

Arithmetic operations are expressed in Python as expected:

Example
1.2*3.7
1.1+2.2
3.3/1.1
1.0-42.4711

Decimal numbers can also be given in scientific notation:

Example
1e3 # 10.0**3 oder 1000

Decimal numbers are calculated in Python with fixed precision (so-called double precision), i.e. with approx. 15 significant digits. This is particularly important because it means that a calculation (unlike in a formula) will not be exact and the numerical stability depends on the exact implementation..

Example
1e15+1 # 1000000000000001.0
1e16+1 # 1e+16

The modulo operator calculates the remainder after division:

Example
42.0 % 23.0 # 19.0

Conversion

In general, various data types can be converted to decimal numbers:

Example
float("2.1") # 2.1