Problem with conversion..Please help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Problem with conversion..Please help

  1. #1
    Jonas Guest

    Problem with conversion..Please help


    Hi

    I have a problem converting a textstring.

    The textstring hold a dollar amount like this:
    dollarstring = "200.50"

    What I want to do is to add , for example, 5 dollar to this amount...I have
    tried to convert the string to a currency data type with Ccur(dollarstring)
    and to a Double with Cdbl(dollarstring) but everything I tried removes the
    comma-sign..i.e
    Ccur(dollarstring) gives the result 20050 (the same for Cbdl)

    In VB there's a function called Val that fixes this. Is there any similar
    function I can use from ASP. I thougth I could use the Val function from
    ASP (since most of the Visual Basic functions are possible to run in ASP
    pages). I tried that function in a VB application and it works just fine
    to solve this problem....How can I solve this in my ASP page ???

    Very greatful for answers and suggestions

    /Jonas

  2. #2
    Kent Guest

    Re: Problem with conversion..Please help


    "Jonas" <jonasjohansson70@hotmail.com> wrote:
    >
    >Hi
    >
    >I have a problem converting a textstring.
    >
    >The textstring hold a dollar amount like this:
    >dollarstring = "200.50"
    >
    >What I want to do is to add , for example, 5 dollar to this amount...I have
    >tried to convert the string to a currency data type with Ccur(dollarstring)
    >and to a Double with Cdbl(dollarstring) but everything I tried removes the
    >comma-sign..i.e
    >Ccur(dollarstring) gives the result 20050 (the same for Cbdl)
    >
    >In VB there's a function called Val that fixes this. Is there any similar
    >function I can use from ASP. I thougth I could use the Val function from
    >ASP (since most of the Visual Basic functions are possible to run in ASP
    >pages). I tried that function in a VB application and it works just fine
    >to solve this problem....How can I solve this in my ASP page ???
    >
    >Very greatful for answers and suggestions
    >
    >/Jonas


    Why not convert both your variables to the currency type, add them, and then
    convert back to a string?

    eg. result = String(CCur("$2.50") + CCur("$5.00"))

    This should give you result = "750". From here you could use this code to
    add the decimal point and dollar sign (VBScript):

    result = "$" & Mid(result, 1, (Len(result) - 2)) & "." & Mid(result, (Len(result)
    - 2))

    This should give result = "$7.50"

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center