Results 1 to 9 of 9

Thread: [RESOLVED] CDbl problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    6

    Resolved [RESOLVED] CDbl problem

    Hi,

    I'm currently having a problem with CDbl which I can't seem to solve.
    I run xy.vbs with 1 argument: 0.5
    Now I need to convert that argument to Double using CDbl(oArgs(0))
    However, it throws: 5 instead of 0.5

    The problem is that:
    CDBl(0.5) = 0.5
    CDBl("0.5") = 5

    How can I convert my argument so it'll be handled like CDbl(0.5)

    I also need this for a second CDbl conversion later in my script where I then compare both values.
    The second one is extracted from a string, so kind of the same problem there.
    Last edited by Tenchuu; Aug 12th, 2009 at 09:08 AM.

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Re: CDbl problem

    Quote Originally Posted by Tenchuu View Post
    Hi,

    I'm currently having a problem with CDbl which I can't seem to solve.
    I run xy.vbs with 1 argument: 0.5
    Now I need to convert that argument to Double using CDbl(oArgs(0))
    However, it throws: 5 instead of 0.5

    The problem is that:
    CDBl(0.5) = 0.5
    CDBl("0.5") = 5

    How can I convert my argument so it'll be handled like CDbl(0.5)

    I also need this for a second CDbl conversion later in my script where I then compare both values.
    The second one is extracted from a string, so kind of the same problem there.
    I tried this code.
    Code:
    Dim c 
    c = Cdbl("0.5")
    c = c * 20
    Wscript.Echo c
    I get 10 as the output. So I do believe it works. How are you passing the value to the script?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    6

    Re: CDbl problem

    OK, since I get 100 as an output I tried to insert "0,5". It therefore only recognises the current language format.

    Lesson learnt. Gotta find a way around this since it should be neutral to the local format.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: CDbl problem

    While this is technically for the wrong language (VB6), I suspect your problem will be solved by the advice in the article How can I handle different locales? from our Classic VB FAQs (in the FAQ forum)

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    6

    Re: CDbl problem

    Yea this is VB, I have searched for 3 hours and didn't find any function like that for vbs, however I worked around it with a little function, even though I didn't want to do that.
    Code:
    Function DecimalConversion(number)
        
        demoval = CStr(CDbl(1/2))
        DecimalChar = Mid(demoval, 2, 1)
    	
        if DecimalChar = "," Then
            DecimalConversion = CDbl(Replace(number, ".", ","))
        End If
        
    End Function

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Re: CDbl problem

    Quote Originally Posted by Tenchuu View Post
    Yea this is VB, I have searched for 3 hours and didn't find any function like that for vbs, however I worked around it with a little function, even though I didn't want to do that.
    Code:
    Function DecimalConversion(number)
        
        demoval = CStr(CDbl(1/2))
        DecimalChar = Mid(demoval, 2, 1)
    	
        if DecimalChar = "," Then
            DecimalConversion = CDbl(Replace(number, ".", ","))
        End If
        
    End Function
    So the issue is resolved?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    6

    Re: CDbl problem

    That's more like a workaround, but yeah, one could say it's resolved

  8. #8
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Re: CDbl problem

    Quote Originally Posted by Tenchuu View Post
    That's more like a workaround, but yeah, one could say it's resolved
    How do you pass parameters as an argument to a script, from the command line?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  9. #9
    New Member
    Join Date
    Apr 2018
    Posts
    1

    Re: CDbl problem

    Try using
    Code:
    Val("0.5")

Posting Permissions

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



Click Here to Expand Forum to Full Width