Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Easy conversion - image formats, currencies and distances
If you're converting between distances (inches, feet, metres, centimetres, metres, furlongs or perches), between currecies (dollars, euros, pounds, roubles, lira) or between graphic file formats (.jpg, .png, .gif, .xbm, .tiff), chances are you'll have any one of a large number of different inputs to change to any one of a large number of different outputs. With - for example - 10 currencies, you'll have 100 (one hundred) possible conversions - and the code will get much bigger and less practical with each new currency added.

The solution is to choose an intermediate standard - for example, to convert the incoming currency to the Euro, then from the Euro to the target currency. That reduces your 100 down to 20 conversions .... and if you had 20 currencies, it would reduce 400 down to 40.

I've got an illustrated example of this techinque on our PHP Techniques Workshop - source code here and the code may be run here. It's also in use on our hotel currency page if guests with to pay in Euros or Dollars - that's based on a more general exchange rate convertor here.

Please consider with this technique that you need to be careful to avoid a loss of precision / information at the intermediate stage.

If your intermediate graphic file standard was .jpg ... it would be a poor choice. .jpg is a lossy standard which makes some compromises. Similarly, an 8 bit image standard would not be suitable.

If your exchange rate tables include commission or are not mid-rate, once again the double conversion I advocate above would lead to an incorrectly rounded result with some loss of data or accuracy. (The ECB tables we use ARE midrate, so there's not an issue!)
(written 2008-05-21 08:31:37)

 
Associated topics are indexed under
H312 - PHP - Tips and Techniques

Back to
The tourists guide to Linux
Previous and next
or
Horse's mouth home
Forward to
Looking for files with certain characteristics (Linux / Unix)

Some other Articles
How do Google Ads work?
Old Sarum airfield brings back fond memories
ls command - favourite options
Looking for files with certain characteristics (Linux / Unix)
Easy conversion - image formats, currencies and distances
The tourists guide to Linux
Exchange Rates - PHP with your prices in your users currency
Using cookies and sessions to connect different URLs - PHP
Seeing how others do it - PHP training
Using a utility method to construct objects of different types - Python
1710 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho