Skip to main content

Automated currency conversion in text

I have created a js script to automatically convert currency on page according to the current rate. Lets say I write "$5" and want to show its value in other currencies. I just need to enclose it in a tag with class = "exchange" and voila: $5.
To enable this behavior you need to link jQuery (add <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script> to the head of page) and the script itself (add <script src="https://drclnatj7kvk6.cloudfront.net/currency.js" type="text/javascript"></script> to the bottom of the page).
Script is based on http://fixer.io/ and http://openexchangerates.github.io/money.js/. Fiddle is available here: https://jsfiddle.net/40rr05fb/42/embedded/result/.
Language and displaying currencies can be easily set. Extending the script is also straightforward.

If you dont see the magic, its Google Blogger's issue. Go into the article itself.

Comments

antgraf said…
Since Google prohibited serving js from Google Docs I have put it to Amazon. So you need to use following URL: http://exchange.js.s3-website-us-east-1.amazonaws.com/currency.js instead of https://googledrive.com/host/0Bzvnm_OA8KsCUGVnM3FWZ01Ga3c
antgraf said…
fixer.io changed API and made https available only to paid accounts. So I've changed script to use openexchangerates.org (API is the same). Now everything works ok again.

Popular posts from this blog

Solving MSB6003 Error for ASP.NET Core Docker Image Build

Trying to build a Linux Docker image for ASP.NET Core project with Typescript support leads to a build error "MSB6003: The specified task executable "node" could not be run". The reason is Linux. On Windows, Microsoft.TypeScript.MSBuild includes tsc.exe. On non-Windows platforms, such as in a Docker container, Microsoft.TypeScript.MSBuild does not include ts.exe and instead shells out to a Node for the TypeScript compiler. The official dotnet/sdk Docker images I think included Node at one point in the past, but they no longer include Node. You will either need to make or find a Docker image with both the dotnet-sdk and Node, or configure some multi-stage build involving the official Node image [ 1 ]. Ok, if I know the reason then I will solve it in a minute. I thought. It turned out to be a quest to install the actual version of Node. Official Microsoft's image for dotnet is based on Debian (12 at the moment for .NET 8.0). So, the straight forward way would be u...

C# Line Numbering Control for RichTextBox

I have spent some free time to port a control from VB.Net to C# and refactor it a little bit. This UI control attaches to RichTextBox and displays line numbers for the text. The control has many settings and re-paints quickly and exactly. You may get it here: https://github.com/antgraf/C--Numbered-Lines-Control-for-RichTextBox--LineNumbersControlForRichTextBox-