You need to work with non-US formatted numbers and currencies.

LS functions are locale specific. You can use the setLocale() function to change the current locale you will be working with. Once this locale is set, all locale specific functions will use this local. For more information on what locals are supported in ColdFusion, you can consult your ColdFusion documentation, or access the server.coldfusion.supportedLocales variable.

As you begin working with locale specific functions, you will probably notice that many of these functions have a non-locale specific twin. As a general rule, aside from some minor locale specific differences, the functions are identical. The following are the locale specific versions of some functions we have already covered in this chapter:

lSIsNumeric() is used to directly test a variable to see if it is numeric.  
<cfset newLocal = setLocale("Dutch (Belgian)")>
<cfset testVar = "foo">
<cfoutput>#lSIsNumeric(testVar)#</cfoutput>
NO

The lSCurrencyFormat() function is used to format a number with the locale specific currency format. It is very similar to the dollarFormat() function with one exception. The exception being that lSCurrencyFormat() has an optional type parameter. Type can be: none, local, or international. The Type parameter controls what type of formatting is used with the basic decimal number. For our example, we will ignore this parameter allowing the type parameter to default to the "local" value:

<cfset newLocal = setLocale("Dutch (Belgian)")>
<cfset testNum = -537>
<cfoutput>#lSCurrencyFormat (testNum)#</cfoutput>
-537,00 BF

The lSEuroCurrencyFormat() function is similar to lSCurrencyFormat(), with the exception that if the current local specific country accepts the euro as a local currency, it can also display the euro currency symbol (?), or the international euro sign (EUR).

The lSNumberFormat() function works the same was as numberFormat(), only the mask contents adapt to the local specific settings:

<cfset newLocal = setLocale("Dutch (Belgian)")>
<cfset testNum = "-537">
<cfset testNum2 = "5735">
<cfset testNumTotal = testNum + testNum2>
<cfoutput>
#lSNumberFormat(testNum,"-$_,____.__")#<BR>
#lSNumberFormat(testNum2,"-$_,____.__")#<BR>
--------------<BR>
#lSNumberFormat(testNumTotal,"-$_,____.__")#
</cfoutput>

Running this code produces this output:

BF- 537,00
BF 5.735,00
--------------
BF 5.198,00

This question was written by Jeremy Petersen
It was last updated on January 12, 2006.

Categories

Numbers

Comments

comments powered by Disqus