How to Format Numbers as Percentages in ColdFusion

Save

Like most dynamic programming languages, ColdFusion can perform mathematical operations with the variables that it handles. However, the results that it returns when it performs such calculations are not always visually appealing or easy to understand. Such is the case with long-form decimals. Displaying them as they are, even with a limit to the amount of numbers displayed, does not always accurately convey a meaning to your user. Fortunately, you can display long-form decimals as percentages in ColdFusion without making any changes to the value of the number.

  • Open the ColdFusion document with the variable you wish to display as a percentage.

  • Find or insert the variable that you wish to display. ColdFusion's variable format is the name of the variable between two pound signs, i.e. #DecimalNumber#.

  • Change the variable to the following format:

    NumberFormat(DecimalNumber*100, "__")#%

    The variable will be displayed as if it were multiplied by 100, with a percentage sign after it. The two underscores are the number mask that determine the format by which the number will display. You can place other characters within the mask, such as decimals, commas for thousand separators, and so on.

  • Save and publish your page. When your query is run, your long-form decimals will display as percentages.

References

  • Photo Credit Stockbyte/Stockbyte/Getty Images
Promoted By Zergnet

Comments

You May Also Like

  • How to Graph Polar Equations

    Polar equations are math functions given in the form of R= f (θ). To express these functions you use the polar coordinate...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!