Making Change

This is almost a completely new version of the Change maker script that I originally wrote back in 2007. The script basically takes any amount of money and provides you with a list of the smallest combination of coins and notes that will make up that amount. Since the actual coins and notes differ between countries the script allows you to specify an array containing a list of all the available values. The makeChange() function takes the following parameters.

  1. the amount to be converted
  2. an array of the coin and note values available
  3. The character to use as the decimal point in the list of values in the answer
  4. the leading currency symbol to use
  5. the trailing currency symbol to use (for those currencies that put the symbol after the amount)

The makeChange function does assume that you have previously defined the following format method to take the calculated amounts and convert them to use the appropriate currency symbol and decimals:


You can use this with whatever code that you like that provides the original amount that is to be converted into a list of notes and coins. Just to illustrate how this works the following form simply allows you to enter an amount and the makechange function will be run when you submit the form with the answer updating the sentence below the form.

One way to make change for this amount is press button to find out.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow