Number Formatting

In Coldfusion, there are many ways to format a number using built-in functions within Coldfusion. Someone might need to format a number in order to pass it on to a Google analytics tracker or to display the number on the screen. One function that is easy to use is the DecimalFormat function; it takes only one parameter and it returns the number as a string with two decimal places, and after every three digits on the left, it adds a comma. If you need the number displayed in U.S. currency format, then use the DollarFormat which does the same thing as the DecimalFormat function except that it adds a leading dollar sign. To display the currency as a number to the thousands place, use the NumberFormat(variableName,”9.99”) function which takes two parameters, the number, and a mask.

In PHP, functions number_format and money_format are used with different options in the parameter fields if you would want commas after every thousands place or not. In C#, String.Format function or adding a mask in the console.writeline/response.writeLine function will diplay the number in different formats.