1

The floating point numbers with finite precision are represented with different precision in identical conditions

It is detected and tested on python version 3.x under Linux and Windows. And take the negative effect for the next calculation.

for i in range(100):
    k = 1 + i / 100;
    print(k)
1.0
1.01
1.02
1.03
1.04
1.05
1.06
1.07
1.08
1.09
1.1
1.11
1.12
1.13
1.1400000000000001
1.15
1.16
1.17
1.18
1.19
1.2
1.21
1.22
1.23
1.24
1.25
1.26
1.27
1.28
1.29
1.3
1.31
1.32
1.33
1.34
1.35
1.3599999999999999
1.37
1.38
1.3900000000000001
1.4
1.41
1.42
1.43
1.44
1.45
1.46
1.47
1.48
1.49
1.5
1.51
1.52
1.53
1.54
1.55
1.56
1.5699999999999998
1.58
1.5899999999999999
1.6
1.6099999999999999
1.62
1.63
1.6400000000000001
1.65
1.6600000000000001
1.67
1.6800000000000002
1.69
1.7
1.71
1.72
1.73
1.74
1.75
1.76
1.77
1.78
1.79
1.8
1.81
1.8199999999999998
1.83
1.8399999999999999
1.85
1.8599999999999999
1.87
1.88
1.8900000000000001
1.9
1.9100000000000001
1.92
1.9300000000000002
1.94
1.95
1.96
1.97
1.98
1.99
Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
babaymc
  • 11
  • 2
  • 1
    Possible duplicate of [How to format a floating number to fixed width in Python](https://stackoverflow.com/questions/8885663/how-to-format-a-floating-number-to-fixed-width-in-python) – bgfvdu3w May 16 '19 at 06:06

1 Answers1

0

It is possible to set the precision in the following way:

for i in range(100):
  k = 1 + i / 100;
  print("%.Nf"%k)

Where N - decimal numbers. Keep in mind, that regularly you don't need a lot of them, though the number could be really huge.