SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Formating a number with own function

    Hello
    if we use formatnumber library function in asp it will format the no as per the number format defined in the locale of the server.
    For example
    some number format look like this 34,135,200 (comma seperated)
    some looks like this 34 135 200(blank spaces seperated)

    so does anybody have a vbscript function which do this job.
    Thanks in advance

    best regards
    vimal
    Knowledge is all about Sharing

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use format currency with a switch that will remove any comma delimiters,

    also you can use replace, ie.

    <%

    number = "34,135,200"
    number = replace(number,","," ")

    %>

    this will output

    34 135 200 as requested.

    Gav

  3. #3
    SitePoint Enthusiast afgmail's Avatar
    Join Date
    Jan 2005
    Location
    Houston, TX
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you want the output to be?
    123,456,789 or
    123 456 789
    Scan completed....
    Brain not found.
    filecabin.com : Notepad2

  4. #4
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could set the local identifier to fit that of your country.

    I use
    <%session.lcid = 1033%>
    Check the ASP documentation for your country or what option suits your needs

    Afrika

  5. #5
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello thanks mates for your replies.
    The problem i had was, that in my machine the number format is as per US standard
    ie comma seperated and in server it is blank space seperated, and only few machines have that kind of number format.So when i do the display of data from database if i use the library function formatnumber then it formats as per the system and so in server it formats with blank space and so when that data to be saved, i just check for comma and replace that comma with blank space.but since the number format is different where we dont have comma, i had the problem of saving that formatted value into the database.

    So what i thought was building my own format deformat function so that i dont worry about the formats in server or my local machine.So just wanted to know weather somebody have a format function in vb script.
    Some computers have indian system where numbers are formatted as crores and lakhs and so making our own functon is not an easy task and so what i decided is, just to make a function where i just use the librrary function to format it and replace the blankspace if any with comma and do it for now.But i like to know if somebody have a good idea so that we just a common method.
    with regards
    vimal
    Knowledge is all about Sharing

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, format currency actually has a switch that takes the users ( i think the servers ) regional settings. Give it a try by switching your settings and see what happen,

    With regards to

    Some computers have indian system where numbers are formatted as crores and lakhs and so making our own functon
    I'd suggest either finding the ascii char for that symbol/letter or adding the letter it's self, to the replace end of the function

    I found this::

    http://www.codeproject.com/useritems/CurrencyToWord.asp

    Gav


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •