?
Solved

Regional Settings with VBScript or Javascript

Posted on 2004-09-03
5
Medium Priority
?
3,292 Views
Last Modified: 2012-08-13
I have an XSL Template that gets XML data in English Regional Settings.  However, I need to be able to convert my numbers into whatever regional format is specified by the browser.  Dates were pretty simple to accomplish this.  How do I do numbers?  Is there a function that I can pass in a number and tell the function that this number is in English regional settings, and have that function return the number in my desired format?

Thanks
Nate
0
Comment
Question by:nalwine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:frugle
ID: 11975985
Session.LCID = 2057

will set an English (British) Locale, I guess you just need to get the browser language and compare with a list of locales.

Response.Write FormatNumber(num, 2, -2) 'Formats the number (num) with 2x decimal points and uses the default locale.

a good list of LCID can be found at http://www.juicystudio.com/tutorial/asp/lcid.asp

Mike
0
 

Author Comment

by:nalwine
ID: 11977632
ok,

this does what I want:

var localval = new Number("<xsl:value-of select="DecimalParameterValue" />");
Production.actual = localval.toLocaleString();

But!!!!  I was wrong about my dates.  I was doing a dateformat, but it turns out dateformat was just taking my english date and treating it as already regional format.  (ie, it looked right but it wasn't)  

So I will award these points to whoever can answer this question:
How do I take an American Date (8/31/2004 13:00:00) and convert it to its proper regional format eg if the browser is set to German--(31.8.2004 13:00:00)?

toLocaleString will not work because it has to be just numbers no words.

nate
0
 
LVL 10

Accepted Solution

by:
frugle earned 1000 total points
ID: 11978080
What is the effect of adding:

<% Session.LCID = 1031 %>

to the top of your script?

am I barking completely up the wrong tree with LCID?

from MSDN: The LCID refers to how dates, times, and currency are formatted for a specific geographical locale.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_vbom_sesoplcid.asp

Mike
0
 

Author Comment

by:nalwine
ID: 11995533
Unfortunately I am not working with ASP in this instance.  So I don't believe it is possible to do what you're saying.  However, I was able to get the numbers to be formatted the way I was wanted by the javascript I included above.

So that being said, here is my final issue with this page.  This is actually a XML Page being transformed by an XSL Template.  In the XML I have two dates, each in the following format: mm/dd/yyyy hh:nn:ss       I can split these apart to get the month, day, and year very easily.  But I need to know either a)how to reconstruct it according to short date format as specified in the regional settings.  or b)Pass the month, day, and year into some sort of javascript or vbscript object and be able to print the date to the page in the short date format as specified by regional settings.

any ideas?

thanks
0
 

Author Comment

by:nalwine
ID: 11996218
ok, this issue has been solved and I will award to points to frugle, however this was the solution I came up with:

Step 1)

Create the following VBScript Function:
<script language="vbscript">
Function FormatDateString(year, month, day, time)
  Dim strDate, retstring
  strDate = DateSerial(year,month,day)
  retstring = FormatDateTime(strDate, 2) + " " + time
  FormatDateString = retstring
End Function
</script>      



Step 2)

In my javascript I did the following:


var StartTime = "<xsl:value-of select="Value" />";
var myArray = StartTime.split('/');
var month = myArray[0];
var day = myArray[1];
var year = myArray[2];
myArray = year.split(' ');
year = myArray[0];
var time = myArray[1] + ' ' + myArray[2];
var dStartTime = FormatDateString(year, month, day, time);
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question