A quibble: truncating
is the wrong thing to do, and is the problem with your original int()
solution in the first place. Rounding
to the nearest cent is the right thing to do (which can be done through round()
as I suggested, or using the sprintf()
solutions that others have mentioned).