Copy link to clipboard
Copied
I have to output 12 dollar amounts, one per month in a table with width 760.
The figures are rather large, like $285,025.46, $155,891.77, $6,961,692.85...etc.
They obvisouly will not fit in the table and will cause it to expand. What can I do to reduce the size and have it still be readable, such as 6.9M, or something like that, for the 6 million number ?
Or is there a better way to do this ?
Copy link to clipboard
Copied
Hope this helps...
<!--- Set amount to make it easier to manipulate --->
<cfset myAmount = "$6,961,692.85" />
<!--- Remove non numeric characters --->
<cfset myAmount = REReplace(myAmount, "\$|\.|,", "", "ALL") />
<!--- Divide amount by one million --->
<cfset myAmount = myAmount / 100000000 />
<!--- Output amount in whole million/s and/or percentage of million --->
<cfoutput>#DollarFormat(myAmount)# M</cfoutput>
Copy link to clipboard
Copied
It's all right to append the M, if that's what you like. You could even implement it as a function, as follows
<cfscript>
function formatAmount(amount) {
if (amount gt 1000000) {
amountInMillions = amount/1000000;
amountFormatted = dollarFormat(amountInMillions) & "M";
} else {
amountFormatted = dollarFormat(amount);
}
return amountFormatted;
}
</cfscript>
<cfoutput>
#formatAmount(123450)#<br>
#formatAmount(1234560)#<br>
#formatAmount(12345670)#
</cfoutput>