Classic ASP FormatNumber weirdness
We have a recently internationalized application written in classic ASP. The following code replicates the problem. The value of this field in the recordset is "8.90" and is entered as varchar (255).
session.LCID = 2057
nNumber = recMessages.fields(lCounter)
Response.Write nNumber '' # prints 8.90
Response.Write FormatNumber(8.90) '' # prints 8.90
Response.Write FormatNumber(nNumber) '' # prints 8.90
session.LCID = 1034
nNumber = recMessages.fields(lCounter)
Response.Write nNumber '' # prints 8.90
Response.Write FormatNumber(8.90) '' # prints 8,90
Response.Write FormatNumber(nNumber) '' # prints 890,00!
What's going on here? Why would it multiply the number by 1000 for certain locales?
+2
source to share
3 answers
Different locales use different characters as decimal and thousands of separators. Although the period (.) Is the decimal separator in the 2057 locale, it is most likely used as the thousands separator in the 1034 locale.
To work around this problem, you can try replacing the dot character in the field value with a specific decimal point separator. I'm not sure, but something like this should work:
session.LCID = 1034
strDecSep = Mid(CStr(CDbl(3/2)), 2, 1)
nNumber = recMessages.fields(lCounter)
nNumber = Replace(nNumber, ".", strDecSep)
0
source to share