Results 1 to 4 of 4

Thread: ColdFusion samples for formatting numbers with NumberFormat

  1. #1
    Join Date
    May 2009
    Tulsa, OK

    Default ColdFusion samples for formatting numbers with NumberFormat

    It is easy to control the way numbers are formatted in ColdFusion using the NumberFormat function. Here is a sample, where we seed the number, and then display it with three different formats using the NumberFormat function:

    <cfset TestNum = -12345678.9>
    #NumberFormat(TestNum, ',')#<BR>
    #NumberFormat(TestNum, '$,')#<BR>
    #NumberFormat(TestNum, '()$,_________.00')#<BR>
    The resulting display would be:

    $( 12,345,678.90)
    The first line just tells it to display the number, with every 3rd decimal place separated by with a comma.

    The second line does the same as the first line, but additionally displays a $ to the left of the number.

    The third line builds on the first two lines, by having the number how with () to indicate a negative number instead of the default - sign, and also has a specific set of place holder's using the _ and also requires the cents to be formatted, including the .00 placeholders if needed.

  2. #2
    GuidoTSarducci Guest

    Default Best datatype for telephone number and how to format?

    What is the best datatype to use for a telephone number and how do you format
    it in ColdFusion to appear like this (999) 999-9999 ?

  3. #3
    Join Date
    Nov 2009



    You would just store the phone number as a normal number, then format it after retrieving it from the database:

    <cfset phone=9189189118>
                areacode = left(phone, 3);
                  firstthree = mid(phone, 4, 3);
             lastfour = right(phone, 4);
     phone_formatted = "(#areacode#)#firstthree#-#lastfour#"
    A more elegant solution would be to create your own function for this as shown at this tutorial from

  4. #4
    GuidoTSarducci Guest

    Default Great!

    I followed your "elegant solution" advice and created a udl and it works great! Thanx!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts