views:

491

answers:

3

We have a recently internationalised application written in classic ASP. The following code replicates the issue. The value of that field in the recordset is "8.90" and is typed 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 is going on here? Why for certain locales would it multiply the number by 1000?

+3  A: 

Hi Simon,

From what you've provided it looks as if the . in 8.90 is being treated as the thousand separator. Is LCID 1034 Spanish?

I'm not sure but I think if you check the number formatting for that locale it will use period as the separator.

Cheers

David A Gibson
Yep, that was it. We fixed it by wrapping FormatNumber in a function that converts the string to a number (in a non-locale sensitive way) and then calles FormatNumber on that.
Simon
A: 

On different locales, different characters are used as decimal and thousand separators. While dot (.) is a decimal separator on the 2057 locale, it's most likely used as a thousand separator on the 1034 locale.

To workaround the issue, you could try replacing the dot character in the field value with the locale-specific decimal 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)
Helen
A: 

It's not that it multiplies by 1000. The number is being formatted to that country's currency format. For instance in the US, 1234.56 would be formatted as $1,234.56, in Spain same number would be 1.234,56

JLopez