Skip to content

round() function gives inconsistent (and incorrect) results sometimes #367

@whaleygeek

Description

@whaleygeek

microbit.org-ticket: 178

TEST PROGRAM (using latest version of Mu as of 24 Oct 2016)

from microbit import *

test of the rounding function to demonstrate errors

scale = 1001
for i in range(1, 100):
result = round((scale/i),1)
print("%s %s" % (i, str(result)))

RESULTS
1 1001.0
2 500.5
3 333.6999
4 250.3
5 200.1999
6 166.8
7 143.0
8 125.1
9 111.2
10 100.1
11 91.0
12 83.39999
13 77.0
14 71.5
15 66.69998
16 62.59999
17 58.89999
18 55.59999
19 52.7
20 50.0
21 47.7
22 45.5
23 43.5
24 41.7
25 40.0
26 38.5
27 37.09999
28 35.79999
29 34.5
30 33.39999
31 32.29999
32 31.3
33 30.29999
34 29.39999
35 28.6
36 27.79999
37 27.1
38 26.3
39 25.7
40 25.0
41 24.39999
42 23.8
43 23.3
44 22.79999
45 22.2
46 21.8
47 21.3
48 20.89999
49 20.39999
50 20.0
51 19.6
52 19.3
53 18.89999
54 18.5
55 18.2
56 17.89999
57 17.6
58 17.3
59 17.0
60 16.7
61 16.39999
62 16.1
63 15.9
64 15.6
65 15.4
66 15.2
67 14.9
68 14.7
69 14.5
70 14.3
71 14.1
72 13.9
73 13.7
74 13.5
75 13.3
76 13.2
77 13.0
78 12.8
79 12.7
80 12.5
81 12.4
82 12.2
83 12.1
84 11.9
85 11.8
86 11.6
87 11.5
88 11.4
89 11.2
90 11.1
91 11.0
92 10.9
93 10.8
94 10.6
95 10.5
96 10.4
97 10.3
98 10.2
99 10.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions