1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Making Change

Friday February 20, 2009
What coins/notes do I need to use to pay $x.xx in change? JavaScript can give the answer.

If you have any sort of JavaScript processing in a form on your web page that deals with money then one of the things that you may be calculating is the amount of change that someone needs to be given. Rather than just presenting that as a single figure, wouldn't it be much friendlier if you could instead provide a list of the notes and coins that are needed to make up that change? This simple JavaScript will add that functionality to your processing. All you need to do is to set up an array containing a list of the coins and notes in your chosen currency (from smallest to largest) and pass in the amount of change to be given and this function will return an array containing the change required.

Making Change
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.