/* Only works with Prototype 1.6 */
Object.extend(String.prototype, {
	toFloat: function() {
		f = parseFloat(this.gsub(/[^0-9\.]/, ''));
		return (isNaN(f)) ? 0.0 : f;
	},
	
	/* only supports . as separator because of parseFloat use */
	toCurrency: function(o) {
		var dollars = 0, cents = 0;
		var options = $H({ precision:2, unit:'' }).merge(o)
		var amount  = new String(this).gsub(/[^0-9\.]/, '');
		var parts   = amount.split('.');

		if (parts.length > 1) {
			dollars = parts[0];
			cents = parts[1];
		} else {
			dollars = parseInt(parts[0]);
			cents = 0;
		}

		if (isNaN(parseInt(dollars))) { dollars = 0; }
		if (isNaN(parseInt(cents))) 	{ cents = 0; }
		return options.get('unit') + parseFloat(dollars + '.' + cents).toFixed(options.get('precision'));
	}
});

Object.extend(Number.prototype, {
	toCurrency: function() {
		return new String(this).toCurrency();
	}
});
