Using the Locale Identifier (LCID) (1)

80酷酷网    80kuku.com

  Introduction:
When you use the VBScript functions FormatNumber, FormatDateTime, and FormatCurrency, the output displayed is based upon the regional settings of your Web server. (To learn more about these functions check out the technical docs (FormatCurrency | FormatDateTime | FormatNumber) or this FAQ.) For example, if you have your regional settings to English - United States, when running the following code from an ASP page:

Response.Write FormatNumber(123456789) & "
"
Response.Write FormatCurrency(987654321)  


You will get the following output:
123,456,789.00
$987,654,321.00

Note that both include two digits after the decimal by default, that set of three digits to the left of the decimal place is grouped by a comma, and that the decimal place is represented by a period. While US visitors may be accustomed to this format, many Europeans are more familiar with a system that uses spaces instead of commas and commas instead of periods.

For example, someone from France may be more comfortable with the following output:
123 456 789,00
987 654 321,00 F

Of course, due to exchange rates, 987,654,321 francs and 876,654,321 dollars are not equivalent, but a visitor from France would, most likely, prefer to see monetary rates in their natural currency.

Regional Settings:
The values FormatNumber and FormatCurrency functions output is customizable, based on the regional settings of the Web server. To alter the Web server's regional settings you need to have Administrator access to the machine itself. Start by opening the Control Panel (Start/Settings/Control Panel) and double click on the Regional Options icon. This will open a dialog box similar to the one below. In the first tab, you can select the Web server's default locale setting. There are a plethora of locales you can select, all of them highly customizable.



Take a moment to examine the dialog box: notice that there are tabs for the Numbers, Currency, and Date and Time for the selected locale. These settings are all customizable. So, if you chose your locale to be English (United States) but wanted to, by default, show four digits after the decimal place, you could move over to the Numbers tab and make this option. The screenshot below is of the Numbers tab showing all of the settings you can specify for the selected locale.



While specifying a default locale setting, which inherently effects the output of VBScript's Format functions, is useful and handy, what if we want to, for some users or for some occassions, use a different locale setting? How can we accomplish this? We'll examine exactly how to using the LCID property of the Session object in Part 2. 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: