How to truncate a number to 2 decimal places in ColdFusion?

How can I take some variables and display them only up to two decimal places, but leave the variables themselves unchanged?

I tried

NumberFormat( reportData ,'0,00') 

But the numbers remained the same.

+7
source share
2 answers

, is the separator for thousands, and 0 means "pad with zero", which can be read

+15
source

If you are in a country where the decimal separator matters, rather than . , then you should use LSNumberFormat , Either in combination with SetLocale , or by specifying the locale attribute of the function. eg.

 <cfoutput>#LSNumberFormat(reportData, "0.00", "Swedish")#</cfoutput> 

OR

 <cfscript>setLocale("Swedish");</cfscript> <cfoutput>#LsNumberFormat(reportData, "0.00")#</cfoutput> 

Note that in the mask attribute we are still using . as a decimal separator. This is then converted to any Swedish decimal point separator (comma).

+12
source

All Articles