Skip to main content
Inspiring
November 11, 2009
Question

Outputting large dollar amounts - how can I reduce ?

  • November 11, 2009
  • 2 replies
  • 500 views

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 ?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
November 11, 2009

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>

chrisbowyer
Known Participant
November 11, 2009

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>