by Rod Martin - GUI Computing
In the last issue of the AVDF I talked about my function for rounding any currency value to the nearest 5 cents - what is commonly referred to as 'Copper coin rounding'.
A number of readers replied with suggestions to increase the speed of the conversion - the best were from Peter Murphy and Targ Parsons (who both came up with the similar formulae).
As you can see, both Peter's and Targ's respective formulae are simpler than mine, while still producing the correct results. They are also much faster. For a given repeated loop of code I used, my formula took 513 seconds, Peter's took 367 seconds and Targ's took 356 seconds. As Targ pointed out, wherever possible, it's better to multiply by a constant rather than divide. This explains why his formula is marginally faster than Peter's. Also, both Targ and Peter have removed all unnecessary brackets. Thanks to all who responded to my original article.