Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Putting a decimal in results - ASP?

  • 21-04-2008 10:36AM
    #1
    Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭


    Does anyone know how to take a returned value from a MYSQL DB, in ASP and always place a decimal point two digits to the left?

    I have a very simple ASP page that connects to a MYSQL DB and returns a value, below is the code:

    userid = Request.Form("USERNAME")
    objConn.Open(sConnection)
    Set objRS = objConn.Execute("SELECT * FROM tbluseracct where actUserID = '" & USERID &"'")

    The value come back fine but its held in interger format, i.e 1435 would mean €14.35. Does anyone know a simple way to take this value and format it correctly in the output? I can add the € sign fine but I am not sure about adding the decimal in 2 place every time?

    Newbie BTW, in case I insult anyone!


Comments

  • Registered Users, Registered Users 2 Posts: 706 ✭✭✭DJB


    you can do something like this within your loop:

    sValue = rs("Value") 'this gets the value of 1435 into a variable. amend to suit your naming conventions
    sValueNew = "&euro" & Left(sValue,len(sValue)-2) & "." & Right(sValue,2)

    sValueNew now has the formatted value in it.

    HTH

    Dave


  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    DJB wrote: »
    you can do something like this within your loop:

    sValue = rs("Value") 'this gets the value of 1435 into a variable. amend to suit your naming conventions
    sValueNew = "&euro" & Left(sValue,len(sValue)-2) & "." & Right(sValue,2)

    sValueNew now has the formatted value in it.

    HTH

    Dave

    Thanks for this, but one question....will this work for a result like 10000 that should be 100 euro? Thanks


  • Registered Users, Registered Users 2 Posts: 6,475 ✭✭✭MOH


    Just divide it by 100?


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Why not try the uber sekrit FormatCurrency function...

    http://www.w3schools.com/vbscript/func_formatcurrency.asp

    First divide by 100 and then apply the format


Advertisement