I would suggest initially multiplying both 'tendered' and 'price' by 100 and using 'round' on the result:
tendered = round(100*tendered);
price = round(100*price);
so as to represent pennies instead of dollars. Similarly your 'denoms' should each be 100 times as great. After that you will be working strictly with integers and have no need for such stuff as "while change+75*eps>=denoms(k)". In fact you can use the 'mod' function to accomplish in one step a whole 'while' loop computation. Of course at the last step you need to divide 'amt_ret' by 100 to get back to dollars.
1 Comment
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/388384-where-can-i-use-round-function-to-make-the-function-perfect#comment_545571
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/388384-where-can-i-use-round-function-to-make-the-function-perfect#comment_545571
Sign in to comment.