fretje
fretje

Reputation: 8382

Reliably convert a string to a double independent of regional settings in classic ASP?

I'm working on a legacy classic ASP interface between our client application and the server. This is not a website, just an intermediate layer in ASP (I know this is not the preferred way of doing things, told you it's legacy and it can - unfortunately - not be changed at this point).

So I'm sending a double value as a parameter on the query string like this:

http:\\localhost\virtdir\myobject.asp?f=function&1=5.25

Now in ASP, I take that value and pass it on to a method on a COM component (myobject is an instance of that COM component) using CDbl to cast the string value to a double:

myobject.DoMethod(CDbl(Request.QueryString("1")))

(Actually, I don't think I have to use CDbl here, as this will be casted implicitly because the COM method takes a double as parameter?)

My problem now is that this doesn't work if in the regional settings of the server a ',' is used as decimal separator. In that case I have to pass "5,25" on the query string to make it work.
As the client doesn't know about the regional settings of the server, is there any reliable way to make sure that a cast to CDbl will always work with the same decimal separator, regardless of the regional settings? Or is there another function like CDbl which does this? Thanks!

Upvotes: 0

Views: 2762

Answers (1)

NakedLuchador
NakedLuchador

Reputation: 991

you could force the "current culture" using this before calling cdbl

SetLocale(1033) 
Session.LCID = 1033

Upvotes: 2

Related Questions