Ask coding questions

← Back to all posts
math inaccuracy - just doing subtraction
GregBeutler

100-65 = 35
so I should get 1 quarter
and 1 dime. but the math has got too much of a rounding down error.

please fix that.
thanks
Greg

Voters
GregBeutler
Comments
hotnewtop
XunPeterson

it's very interesting, thanks.

[deleted]

It may be better to work with cents, so $1 => 100, quarters => 25, and so on. I have written a Python program to work out change. I can let you know the URL if your program is not part of a homework/assignment problem.

GregBeutler

@malvoliothegood thanks for the offer, I'll just use the round function - which I didn't think I needed to.

Roar123

That is pretty weird! You should use round(number, places) to prevent this.

GregBeutler

@Roar123 yeah, I didn't think it would happen in a million years, but that's why we test. ;)