Update Column to add Decimal Point

Discussion in 'ASP General' started by Simon Gare, Apr 16, 2007.

  1. Simon Gare

    Simon Gare Guest

    Hi all,

    have a 'money' field in the SQL 2000 table that users enter 200 (for example
    which represents £2.00) without the decimal point, what I need is to have a
    command or something that adds the decimal point before the last 2 digits,
    so user enters 200 and the value stored in the table is 2.00 bearing in mind
    that this value could be anything from 1.00 to 50.00.

    The user enters the data from an asp page on a touch screen device.

    Regards
    Simon

    --
    Simon Gare
    The Gare Group Limited

    website: www.thegaregroup.co.uk
    website: www.privatehiresolutions.co.uk
    Simon Gare, Apr 16, 2007
    #1
    1. Advertising

  2. Simon Gare

    Evertjan. Guest

    Simon Gare wrote on 16 apr 2007 in
    microsoft.public.inetserver.asp.general:

    > Hi all,
    >
    > have a 'money' field in the SQL 2000 table that users enter 200 (for
    > example which represents £2.00) without the decimal point, what I need
    > is to have a command or something that adds the decimal point before
    > the last 2 digits, so user enters 200 and the value stored in the
    > table is 2.00 bearing in mind that this value could be anything from
    > 1.00 to 50.00.
    >
    > The user enters the data from an asp page on a touch screen device.


    <script language='jscript' runat='server'>

    function addDecPoint(x){
    var s = (x<0)?'-':'';
    x = Math.abs(x);
    x=(x<100)?((x+1000)+'').substr(1):''+x;
    return s + x.replace(/(\d\d)$/,'.$1');
    };

    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Apr 16, 2007
    #2
    1. Advertising

  3. Simon Gare

    Simon Gare Guest

    ok,

    field in the table is called car_park the asp page is slightly more
    difficult as the user enters the data via a .swf file. can this be run as a
    command somewhere else, below is the code on the asp file (bearing in mind
    that there is not actual text field here) some more assistance would be
    appreciated.

    Dim id, waiting, carPark
    Dim driverNo, sId

    Dim sql, conn

    Dim sResponse

    sResponse = ""

    id = Request.Form("id")
    waiting = Request.Form("waiting")
    carPark = Request.Form("carPark")

    driverNo = Request.Form("driverNo")
    sId = Request.Form("sId")

    If (Len(id) = 0 OR NOT IsNumeric(id)) OR Len(waiting) = 0 OR Len(carPark)
    = 0 OR Len(driverNo) = 0 OR Len(sId) = 0 Then
    Response.Write("end_done=ERROR")
    Response.End()
    End If

    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open g_connectionString

    ' Updating booking_form...

    sql = "UPDATE booking_form SET waiting_in_minutes='" & waiting & "',
    car_park='" & carPark & "', time_cleared=GETDATE(), allocated='COMPLETED'
    WHERE ID=" & id

    conn.Execute(sql)

    > <script language='jscript' runat='server'>
    >
    > function addDecPoint(x){
    > var s = (x<0)?'-':'';
    > x = Math.abs(x);
    > x=(x<100)?((x+1000)+'').substr(1):''+x;
    > return s + x.replace(/(\d\d)$/,'.$1');
    > };
    >
    > </script>
    Simon Gare, Apr 16, 2007
    #3
  4. Simon Gare

    Evertjan. Guest

    Simon Gare wrote on 16 apr 2007 in
    microsoft.public.inetserver.asp.general:

    [Please do not toppost on usenet]
    Topposting corrected


    >> have a 'money' field in the SQL 2000 table that users enter 200 (for
    >> example which represents £2.00) without the decimal point, what I
    >> need is to have a command or something that adds the decimal point
    >> before the last 2 digits, so user enters 200 and the value stored in
    >> the table is 2.00 bearing in mind that this value could be anything
    >> from 1.00 to 50.00.



    >> <script language='jscript' runat='server'>
    >>
    >> function addDecPoint(x){
    >> var s = (x<0)?'-':'';
    >> x = Math.abs(x);
    >> x=(x<100)?((x+1000)+'').substr(1):''+x;
    >> return s + x.replace(/(\d\d)$/,'.$1');
    >> };
    >>
    >> </script>


    > ok,
    >
    > field in the table is called car_park the asp page is slightly more
    > difficult as the user enters the data via a .swf file. can this be run
    > as a command somewhere else, below is the code on the asp file
    > (bearing in mind that there is not actual text field here) some more
    > assistance would be appreciated.
    >
    > Dim id, waiting, carPark
    > Dim driverNo, sId
    >
    > Dim sql, conn
    >
    > Dim sResponse
    >
    > sResponse = ""
    >
    > id = Request.Form("id")
    > waiting = Request.Form("waiting")
    > carPark = Request.Form("carPark")
    >
    > driverNo = Request.Form("driverNo")
    > sId = Request.Form("sId")
    >
    > If (Len(id) = 0 OR NOT IsNumeric(id)) OR Len(waiting) = 0 OR
    > Len(carPark)
    > = 0 OR Len(driverNo) = 0 OR Len(sId) = 0 Then
    > Response.Write("end_done=ERROR")
    > Response.End()
    > End If
    >
    > Set conn = Server.CreateObject("ADODB.Connection")
    > conn.Open g_connectionString
    >
    > ' Updating booking_form...
    >
    > sql = "UPDATE booking_form SET waiting_in_minutes='" & waiting &
    > "',
    > car_park='" & carPark & "', time_cleared=GETDATE(),
    > allocated='COMPLETED' WHERE ID=" & id
    >
    > conn.Execute(sql)


    Where is your money field you specified in the original posting I added
    above???

    And you specified a value coming FROM a database, so I would need to se a
    SELECT SQL, not an UPDATE SQL, meseems.

    ===================================================

    You can easily change the integer cents value coming from that field in
    vbscript and write that:

    <% 'vbs
    response.write "£ " & addDecPoint(centsValueFromDatabase)
    %>

    The jscript part can be put anywhere in the vbs-using asp page,
    usually I put it at the bottom.



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Apr 16, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ven
    Replies:
    3
    Views:
    1,317
  2. Gilbert Fine
    Replies:
    8
    Views:
    896
    Zentrader
    Aug 1, 2007
  3. Vitaliy
    Replies:
    1
    Views:
    471
    Peter Otten
    May 29, 2008
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,321
    Saraswati lakki
    Jan 6, 2012
  5. PERO
    Replies:
    4
    Views:
    453
    Brian McCauley
    Apr 13, 2007
Loading...

Share This Page