![]() ![]() ![]() |
||
|
Typically, a function acts on data. It can generate a value or a set of values, usually from some input. You can perform the following operations (actions) with functions:
You use number signs (#) with functions to display the results of a function on the page. Number signs tell the ColdFusion server to evaluate the content between the number signs and display the value, for example:
<cfoutput> Hello world, <br> Todays date is #DateFormat(Now(), "mm/dd/yyyy")# </cfoutput>
The following figure shows the output of this example:
If you did not include the number signs around the DateFormat(Now(), "mm/dd/yyyy")
function, ColdFusion would not evaluate the function and the previous example would display your source code, as follows:
For more information about how to use number signs with functions, see ColdFusion MX Developers Guide.
All functions have parentheses, regardless of whether the function acts on data. Consider the following function:
#Now()#
If you put anything inside the parentheses of the Now()
function, an error would occur. The Now()
function returns an unformatted date and time. However, you can format the results of this function with other functions, such as the DateFormat()
or TimeFormat()
functions.
Usually, a function performs an operation on a value, and the value can include the value of a variable. For example, to format the value of a variable that contains a value in dollars, the code to write this statement might look like this:
#DollarFormat(price)#
The DollarFormat
function returns a value as a string and formats that value with two decimal places, a thousands separator, and a dollar sign. The number signs (#) around the function instruct ColdFusion to evaluate the content between the number signs and display the value.
Functions can generate data, as well as act on data. Consider the following example:
#DateFormat(Now(), "mm/dd/yyyy")#
In this example, the Now()
function generates the date, and then the DateFormat
function formats the date.
|
||
![]() ![]() ![]() |