Solved

Regional Settings with VBScript or Javascript

Posted on 2004-09-03
5
3,282 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please explain purpose of GZIP 4 61
Make a website not indexable by google 6 29
javascript form - error when hitting enter 3 28
calculate days away 11 31
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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