Archive for the 'travel' Category

Actionscript string replacement and international currency.

This made me a little nostalgic for the olden days when a vacation to Europe was a remote possibility:

var str:String = "Now only $9.95!";
var price:RegExp = /\$([\d,]+.\d+)+/i;
trace(str.replace(price, usdToEuro));
 
function usdToEuro(matchedSubstring:String,
                    capturedMatch1:String,
                    index:int,
                    str:String):String {
    var usd:String = capturedMatch1;
    usd = usd.replace(",", "");
    var exchangeRate:Number = 0.853690;
    var euro:Number = usd * exchangeRate;
    const euroSymbol:String = String.fromCharCode(8364);
    return euro.toFixed(2) + " " + euroSymbol;
}