Problem 48. Making change
Given an amount of currency, return a vector of this form:
[100 50 20 10 5 2 1 0.5 0.25 0.1 0.05 0.01]
Example:
Input a = 257.68
Output b is [2 1 0 0 1 1 0 1 0 1 1 3]
Always use bigger bills/coins if possible.
Solution Stats
Problem Comments
-
9 Comments
Show
6 older comments
Serhii Tetora
on 9 Jan 2019
Why function roundn is undefined?
Brandon
on 23 Jun 2023
A lot of people are adding an amount smaller than a cent to the input to get around floating point issues. There are two other ways to get around this. One is to make the last cent 0.00999 instead. The other is to change your comparison line to compare against a slightly smaller/larger value.
Reuben
on 14 Nov 2024
my first floating point issue, yay
Solution Comments
Show commentsProblem Recent Solvers3426
Suggested Problems
-
26527 Solvers
-
Remove any row in which a NaN appears
8672 Solvers
-
6779 Solvers
-
Project Euler: Problem 7, Nth prime
1583 Solvers
-
Back to basics 22 - Rotate a matrix
921 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!