• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Formatting Functions

Formatting Functions

ColdFusion can do some of the preparatory work that must be completed before displaying a value. The following are some of the more popular CFML formatting functions:

  • DateFormat(date,mask)— Formats date according to the specified mask. A mask of “mm/dd/yy", for example, would yield a date in the form 11/30/02. For example:

    <cfoutput>#DateFormat(Now(),"mm/dd/yy")#</cfoutput>
    						
  • DollarFormat(number)— Returns number formatted as a dollar amount with a dollar sign, decimal point, and commas where necessary. For example:

    The price for this item is <cfoutput>#DollarFormat(price)#.</cfoutput>
    						
  • HTMLEditFormat(HTMLcode)— Removes reserved characters within the string HTMLcode and replaces them with their escaped values. The less than sign (<), for example, would be replaced with &lt;. Now consider this example:

    <cfset escapedHTML = HTMLEditFormat(unescapedHTML)> 
    
  • NumberFormat(number,mask)— Returns number formatted according to the specified mask. For example, a mask of “_,___.__” would produce a number in the form 1,000.00. Now consider this example:

    Pi to two digits after the decimal is
    <cfoutput>#NumberFormat(Pi(),"_.__")#</cfoutput>.
    						
  • ParagraphFormat(string)— Removes consecutive carriage return and line feed characters from string and replaces them with <p> elements. For example:

    <cfset formattedEssay = ParagraphFormat(Form.essay)>
    						
  • TimeFormat(time,mask)— Formats time according to the specified mask. A mask of "hh:mm:ss TT", for example, produces a time in the form 07:25:00 AM. Now consider this example:

    The current time is <cfoutput>#TimeFormat(Now(),"hh:mm:ss tt")#</cfoutput>. 
    
    
    					  
  • URLEncodedFormat(string)— Encodes string so that it can be successfully passed as a value in a query string. For example:

    <cfoutput> 
    <a href="profile.cfm?name=#URLEncodedFormat(employeeName)#">
    View #employeeName#'s profile
    </a>
    </cfoutput>
    						

    NOTE

    If you're familiar with JavaScript, the URLEncodedFormat() function does the same thing as the JavaScript escape() function.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint