Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Outputting large dollar amounts - how can I reduce ?

Participant ,
Nov 10, 2009 Nov 10, 2009

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 ?

TOPICS
Getting started
459
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2009 Nov 10, 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 11, 2009 Nov 11, 2009
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources