4/28
Part 1 of 7 · Floats to centsLearn and do

int cuts 0.29 down to 28 cents, round doesn't

The obvious conversion is int(x * 100). It's wrong. Here it is next to round(x * 100):

print("dollars  x * 100             int  round")
for x in [0.07, 0.30, 0.29, 0.57, 1.15]:
    print(f"{x:<8.2f} {x * 100!r:<19} {int(x * 100):<4} {round(x * 100)}")
Predict

What does int(1.15 * 100) give?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

Over the 100,000 amounts from $0.01 to $1,000.00, how many does int get wrong, and how many does round?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

What do round(0.125 * 100) and round(13.5) give?

Pick one to see what it prints.
Pick an answer above to see the rest