I'm trying to do some currency formatting in a Flash CFForm.
I've created and included a function from the O'Reily website that does
just this, as actionscript doesn't have a numberformat() function. I've
bound a text cfformitem to a call to the function passing in the number
of decimal places, the currency symbol and a reference to a field that
contains the number to be formatted and displayed, but I'm just getting
a blank. I tried sticking an alert into the function to see if it was
calling the function, but it doesn't appear to be calling the function.
I'm not getting any errors in the runtime log or anywhere else that I
can think of, I'm just not getting anything back.
Here's my code..... (well some of it anyway...)
The function definition :
<cfsavecontent variable="onLoad">
_global.currencyFormat = function (num, decimalPl, currencySymbol,
thousandsDelim,
decimalDelim, truncate, spaceFill) {
// Default to two decimal places, a dollar sign ($), a comma for
thousands,
// and a period for the decimal point. We implemented the defaults using
// the conditional operator. Compare with Recipe 5.5.
decimalPl = (decimalPl == undefined) ? 2 : decimalPl;
currencySymbol = (currencySymbol == undefined) ? "$" : currencySymbol;
thousandsDelim = (thousandsDelim == undefined) ? "," : thousandsDelim;
decimalDelim = (decimalDelim == undefined) ? "." : decimalDelim;
// Split the number into the whole and decimal (fractional) portions.
var parts = String(num).split(".");
// Truncate or round the decimal portion, as directed.
if (truncate) {
parts[1] = Number(parts[1]) * Math.pow(10, -(decimalPl - 1));
parts[1] = String(Math.floor(parts[1]));
} else {
// Requires the roundDecPl( ) method defined in Recipe 5.3
parts[1] = Math.roundDecPl(Number("." + parts[1]), decimalPl);
parts[1] = String(parts[1]).split(".")[1];
}
// Ensure that the decimal portion has the number of digits indicated.
// Requires the zeroFill( ) method defined in Recipe 5.4.
parts[1] = Math.zeroFill(parts[1], decimalPl, true);
// If necessary, use the numberFormat( ) method from Recipe 5.5 to
// format the number with the proper thousands delimiter and leading
spaces.
if (thousandsDelim != "" || spaceFill != undefined) {
parts[0] = Math.numberFormat(parts[0], thousandsDelim, "",
spaceFill - decimalPl - currencySymbol.length);
}
// Add a currency symbol and use String.join( ) to merge the whole
(dollar)
// and decimal (cents) portions using the designated decimal delimiter.
alert(currencySymbol + parts.join(decimalDelim));
return currencySymbol + parts.join(decimalDelim);
};
</cfsavecontent>
The onLoad call that defines the function.
<cfform name="OrderForm" method="post" preloader="no" format="flash"
height="850" width="500" skin="haloblue"
onload="#variables.onload#">....</cfform>
The call to the function.
<cfformitem type="text"
bind="{_global.currencyFormat(OrderForm.subtotal,2,'£')}"
style="text-align:left" />
Any help asap would be greatly appreciated.
Regards
Stephen
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:216833
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54